I have a data model as follows
- A bid is associated with the
Userthat placed the bid - A bid may be either an
offeror alistingon a singleProduct - A
Productmay have multiple offers and listings (separate) posted by multiple users - A user may place offers and listings on multiple
Products
Product <— Bid —> User
Given an existing p from the Product model, operations like p.offers << bid where bid is a new instance of the Bid class do not mark p as “dirty” and changes are not persisted to the database
Product class
class Product
include Mongoid::Document
...
embeds_many :offers, class_name: 'Bid'
embeds_many :listings, class_name: 'Bid'
end
Bid class
class Bid
include Mongoid::Document
belongs_to :user
belongs_to :product
field :amount, type: Money
field :timestamp, type: DateTime, default: ->{ Time.now }
end
Additionally, calling bid.save! or creating a new array p.offers = Array.new [bid] do not seem to work either
Updated:
Your model structure should be