On Sunday, May 24, 2015 at 9:30:48 AM UTC-7, Igor Bochkariov wrote:
>
> I'm migrating from DataMapper to Sequel and I have the following model
> with association:
>
>
>> class Page < Sequel::Model
>> many_to_one :parent, :class=>self
>> one_to_many :children, :key=>:parent_id, :class=>self
>> # alias_method :children, :children_dataset
>
>
> I would like to construct the following requests:
> `Page.first.children.where(filter).order(:path)` but the default getter
> `children` returns an unordered unfiltered array.
>
> Is it safe to alias method `children` to `children_dataset` and use it as
> a dataset? Is there better or standard way to do what I want?
>
Aliasing would not be safe. The Sequel way to do what you want would be to
pass a block:
Page.first.children{|ds| ds.where(filter).order(:path)}
If you don't like that approach, you could try the association_proxies
plugin:
http://sequel.jeremyevans.net/rdoc-plugins/classes/Sequel/Plugins/AssociationProxies.html
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.