On Thursday, January 15, 2015 at 6:34:23 PM UTC-8, Roy Lam wrote: > > I have a legacy app that is implemented using the following model > (currently in rails, but i want to port it to sequel): > > class Person < Sequel::Model > one_to_one :parent > > def grand > parent.parent > end > end > > class Parent < Sequel::Model > one_to_one :parent, :class=>:Grand > end > > class Grand < Sequel::Model > end > > The thing is that I just need to access a handful of columns in the grand > table so using model seems a bit overkill. Is there a better way I can just > join the grand table as association without having to define the classes > (Parent and Grand are not really being used)? > > This is what I really want: > select > grand.name as "GrandParent Name" > , ... > from > person > inner join parent on parent.id = person.parent_id > inner join grand on grand.id = parent.parent_id >
In Sequel, this query would be: DB[:person]. join(:parent, :id=>:parent_id). join(:grand, :id=>:parent_id). select(:"grand__name___GrantParent Name") You are not required to use models in Sequel, you can always use datasets if you want to. Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
