We've been using Squeryl with Lift for quite a while and have been very happy with it. Based on your case above, in the current release version of Squeryl (0.9.5), you could do something like:
class BaseProduct(id:Long, some more fields) extends KeyedEntity[Long] {
}
class MyProduct(id:Long, some more fields) extends KeyedEntity[Long] {
}
Then, you would have a schema that defines the relationships like (I am assuming they are joined on the ID field):
val baseProducts = Table[BaseProduct]("base_products")
val myProducts = Table[MyProduct]("my_products")
val myProductsToBaseProducts =
oneToManyRelation(myProducts, baseProducts).via((mp, bp) =>
mp.id === bp.id)
To query both records, you would do something like:
from(myProducts, baseProducts) ( (mp, bp) =>
where(mp.id === bp.id and mp.id === LOOKUPVAL)
select(bp, mp) )
The query above will return a tuple of (BaseProduct, MarketProduct) from a single SQL select.
You can also use the relationship to retrieve the related item, such as by adding this method to MyProduct
:
def baseProduct = myProductsToBaseProducts.left(this)
However, like your example from Mapper, it will issue a second query. As for making database specific queries, there is the &
operator which will allow you to evaluate expressions at the server. If the function is not available in Squeryl you can create custom functions.
Overall, I have found Squeryl to be very flexible and a great hybrid between ORM and straight SQL. It has performed remarkably well and I have not found too many places where Squeryl prohibited me from easily getting at the database functionality that I needed. It gets even easier with the next version, as 0.9.6 will have a lot more flexibility with custom types.