On Friday, August 9, 2013 10:19:58 AM UTC-5, Jeremy Evans wrote: > > On Friday, August 9, 2013 7:56:06 AM UTC-7, Keith Moore wrote: >> >> I am trying to do something similar to what the Sequel::Model does in >> terms of chaining dataset methods. However, I am having some issues in >> doing this. This may be more of a Ruby design question than a Sequel Gem >> question, >> >> However, I am hoping someone can help me with this issue. Here is what I >> am trying to do: >> >> Item < Sequel::Model(:ITEM) >> >> def self.apply_filter(params) >> c = self.clone >> # loop >> c.dataset = c.dataset.where(some criteria here) >> # end loop >> c >> end >> >> end >> >> >> And in my "controller", I want to be able to do something like the below >> where the other apply methods are chained together in a similar fashion. >> >> items = >> Item.apply_filter(params).apply_pagination(params).apply_order_by(params).all >> >> The problem is that I don't get back instances of type Item. They are of >> type Class. >> >> Can someone tell me how I should go about achieving this? >> > > Why do you want to clone the class? If you want instances of type Item, > you shouldn't be cloning the Item class. You probably just want to make > apply_filter a dataset method: > > class Item < Sequel::Model(:ITEM) > dataset_module do > def apply_filter(params) > where(some criteria here) > end > end > end > > Note that this should work with the example code you provided. > > 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/groups/opt_out.
