Hi David, I agree, we have a syntax improvement to be done here. I consider this mostly to be an improvement for the Query Builder API, but could also be to the Query class itself. When I mention the Query Builder API, I mean the builder-API which is exposed when calling DataContext.query()... You might be interested in the class SyntaxExamplesTest in the core module - it showcases some of the query building API use cases. I think we could start defining a "simpler join syntax" in a "syntax test" class like this?
I like your idea of a "fromJoined(Column, Column)". We could even expand it to 2+ column arguments, so that we could define your 3-table join in a single call. Kinda like this (joining based on 3 columns): dc.query().fromJoinOn(col1, col2, col3).select(col1); It would simply be a var-args Column argument I guess. I guess it would be a bit error prone if you pass columns that are not from separate tables, but then again, we can only go so far with the type system. 2014-06-29 19:25 GMT+02:00 David Krause <[email protected]>: > Hi MetaModel users and developers, > > I am looking for a tip, or maybe want to make a proposal... I have three > tables that I do some joining on... For example purpose, let's say they are > called: > > product (id, product_line_id, name) > product_line (id, name) > product_configuration(id, product_id, name, ...) > > Often I want to join like this: > > product p > INNER JOIN product_line ON p.id = product_line.product_id > INNER JOIN product_configuration ON p.id = > product_configuration.product_id > > So in short, just 3 tables with a relationship "on a line" in a E/R > diagram. > > I have been using MetaModel for a small webapp on this database, and it > works well. But I find that the table-joining code here is very bulky. I > need use a lot more lines of Java code than what is there in plain SQL. > Maybe there is a shortcut I don't know of? Or maybe it can be improved. An > idea for improvement would be to have a syntax where the Tables are not > supplied directly, but rather just grabbed if you supply two Columns. For > instance: > > Column productIdPK = [some code omitted]; > Column productLineProductIdFK = [some code omitted]; > > Query q = [some code omitted]; > q.fromJoined(productIdPK, productLineProductIdFK); > > What do you think? >
