diff -r eac38214183d -r 49eb72a46208 src/main/scala/fis/sr/model/ServiceRepoSchema.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/scala/fis/sr/model/ServiceRepoSchema.scala Thu May 24 11:19:26 2012 +0200 @@ -0,0 +1,60 @@ +/* + * Copyright 2012 Tomas Zeman + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package fis.sr.model + +import fis.crm.model.{Company, CrmSchema} +import net.liftweb.squerylrecord.RecordTypeMode._ + +trait ServiceRepoSchema extends CrmSchema { + /* service */ + val serviceT = tableWithSeq[Service] + + val serviceCompany = oneToManyRelation(companyT, serviceT). + via((c, s) => (c.id === s.company)) + + val serviceState = oneToManyRelation(cli, serviceT). + via((i, s) => (i.id === s.stateFld)) + + /* service payment */ + val servicePaymentT = tableWithSeq[ServicePayment] + + val servicePaymentService = oneToManyRelation(serviceT, servicePaymentT). + via((s, p) => (s.id === p.service)) + servicePaymentService.foreignKeyDeclaration.constrainReference(onDelete cascade) + + val servicePaymentPeriod = oneToManyRelation(cli, servicePaymentT). + via((i, p) => (i.id === p.periodFld)) + + val servicePaymentCurrency = oneToManyRelation(cli, servicePaymentT). + via((i, p) => (i.id === p.currency)) + +} + +object ServiceRepoSchema extends ServiceRepoSchema + +object CompanyServices { + def apply(c: Company): Iterable[Service] = + from(ServiceRepoSchema.serviceCompany.left(c))(s => + select(s) orderBy(s.name asc)) +} + +object ServicePayments { + def apply(s: Service): Iterable[ServicePayment] = + from(ServiceRepoSchema.servicePaymentService.left(s))(p => select(p)) +} + + +// vim: set ts=2 sw=2 et: