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?
Thanks!
François
On 21 juin, 19:37, Jeremy Evans <[email protected]> wrote:
>
> In addition to using contacts_dataset, you could also pass a block to
> contacts:
>
> User.first.contacts{|ds| ds.filter(:name => /abc/)}
>
> 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.