Given a many_to_many association,
many_to_many :categories
I want to add an accessor for category_ids.
Until now I was using the following code:
def category_ids
@category_ids || categories_dataset.select_map(:id)
end
def category_ids=(ids)
@category_ids = ids
modified!
end
def after_save
super
if defined?(@category_ids)
self.remove_all_categories
Category.where(:id => @category_ids).each do |c|
self.add_category(c)
end
end
end
I was wondering if there was a better approach.
--
Nicolas Goy
Programmer
--
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.