I've got model User:
class User
field :username, type: String
embeds_many :products
end
class Product
field :name, type: String
embedded_in :user
end
I would like to have single operation that would:
- insert the user
- update the user in case the user exists already (this i can easily do with upsert)
- push the products
This works for upserting:
User.new(username: 'Hello').upsert
The problem is that this will delete the embedded products (the products attribute is not specified).
Can I ask mongoid to skip setting array to empty? Can I ask mongoid to push new products at the end of products array? Something like this:
User.new(username: 'Hello').push(products: [Product.new(name: 'Screen')]).upsert