On Jun 23, 11:26 am, François Beausoleil <[email protected]> wrote: > Related to this, how would I use dataset methods on the target class? > > class User < Sequel::Model(:users) > one_to_many :contacts > end > > class Contact < Sequel::Model(:contacts) > def_dataset_method(:search) do |fragment| > grep([:surname, :rest_of_name], > Regexp.new(Regexp.escape(fragment), Regexp::IGNORECASE)) > end > end > > User.first.contacts.search("a") raises a NoMethodError on Array, again > due to #contacts not being a dataset. I tried to move #search into a > module, and used the :extend option on the #one_to_many call, but this > again raised a NoMethodError on Array. I must misunderstand > how :extend works. > > What I came up with is this: > > class User < Sequel::Model(:users) > > def search_contacts(fragment) > contacts_dataset.search(fragment) > end > > end > > Any pros/cons of using this method? Or should I be doing it some other > way?
That way is fine. Like I mentioned earlier, you can also pass a block to contacts to accomplish something similar. The :extend option affects the association dataset, not the array of objects, as mentioned in the documentation. Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" 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/sequel-talk?hl=en.
