On Sunday, January 18, 2015 at 3:21:43 PM UTC-8, Roy Lam wrote:
>
> Thanks Jeremy,
>
> In my application, I would still need the Person model but the other two
> models can be removed. Is it possible for Person to access the columns in
> the grand table via an instance method? e.g.
> john=Person[1]
> john.grand.name
>
Yes, it's possible, with something like
class Person
Grand = Struct.new(:name, ...)
def grand_ds
db[:person].
join(:parent, :id=>:parent_id).
join(:grand, :id=>:parent_id).
select(:grand__name, ...)
end
def grand
Grand.new(*grand_ds.first.map(Grand.members))
end
end
But I don't see how it's better than just using a model for Grand.
Note that if you don't mind using john.grand[:name] instead of
john.grand.name, you can eliminate the use of the Grand struct.
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.