Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8497955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:16:18+00:00 2026-06-11T00:16:18+00:00

I have a data model as follows A bid is associated with the User

  • 0

I have a data model as follows

  • A bid is associated with the User that placed the bid
  • A bid may be either an offer or a listing on a single Product
  • A Product may 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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:16:20+00:00Added an answer on June 11, 2026 at 12:16 am

    Updated:

    Your model structure should be

    class Product
       include Mongoid::Document
       ...
       has_many :offers, class_name: 'Bid', :inverse_of => :offers_bid
       has_many :listings, class_name: 'Bid', :inverse_of => :listings_bid
    end
    
    class Bid
       include Mongoid::Document
       belongs_to :offers_bid, :class_name => 'Product', :inverse_of => :offers
       belongs_to :listings_bid, :class_name => 'Product', :inverse_of => :listings
       belongs_to :user
    
       field :amount, type: Money  
       field :timestamp, type: DateTime, default: ->{ Time.now }
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a core data model defined as follows: A User has many events.
I have a data model where a User can like a Project, Suggestion, Comment
I have a data model that represents a weekly order. Eg. my order might
I have a data model object User . My app also has some other
Say that I have a data model called Widget . If I pick one
I have an Entity Data Model that I have created, and its pulling in
I have several Core Data model version that I have added to my .xcdatamodeld
I have the following data model: I am writing a WCF service that needs
I have an core data model as follows The attributes property of Page is
At present, I have very successfully architected my applications as follows: Data model (Entity

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.