On 18/05/11 5:27 AM, Emmanuel Gomez wrote:
On May 17, 2011, at 12:44 AM, Xavier (DBIYF) wrote:
We pretty much use the following two functions which allow some degree of
maintainability.
https://gist.github.com/976112
Wowza, that's cool.
I don't understand why you need custom SQL generation in there, though, because
I thought that this:
collection = Admin.all(:role => :super_admin)
DataMapper.repository.adapter.send(:select_statement, collection.query)
would work with any collection, thus supporting arbitrarily-complex queries
that traverse associations, etc.
Are there some places that approach has fallen short for you?
yeah, had to join across multiple tables and only pull out certain
fields and order by not the primary table and etc etc which was just too
hard/not possible with DM query interface. It actually falls out fairly
nice. We tried an ARel variant as well (I hacked it to sit on top of DM)
to try and avoid raw SQL but it was actually uglier and harder to read.
For the most part we do try to stick to the query interface though.
SQL is fairly good for writing queries if you can interpolate in the
boring stuff.
I need to write up a proper blog post for it.
Thank you for sharing, indeed! And please do write up a blog post, I think it
would be of general interest.
Thanks,
Emmanuel
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.