Skip to content

Instantly share code, notes, and snippets.

@yelvert
Created October 20, 2010 06:16
Show Gist options
  • Save yelvert/635876 to your computer and use it in GitHub Desktop.
Save yelvert/635876 to your computer and use it in GitHub Desktop.
mongoid building an embedded many document with a references_many in it saves when it shouldn't
class Formula
include Mongoid::Document
referenced_in :formula_category
field :quantities, :type => Array, :default => []
field :directions, :type => String
embeds_many :formula_medications
end
class FormulaMedication
include Mongoid::Document
embedded_in :formula, :inverse_of => :formula_medications
referenced_in :medication, :inverse_of => :formula_medications
field :concentration
end
class Medication
include Mongoid::Document
field :name, :type => String
field :concentrations, :type => Array, :default => []
field :description, :type => String
references_many :formula_medications
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment