Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jens/437839 to your computer and use it in GitHub Desktop.
Save jens/437839 to your computer and use it in GitHub Desktop.
class Product
include Mongoid::Document
field :name
embeds_many :product_items
has_many_related :articles
def update_product_items
product_items.destroy_all
articles.all.each do |a|
pi = product_items.new( a.attributes.reject{|k,v| k == "_id" || k == "_type" || k == "product_id" })
pi.save
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment