Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account

MongoDB association oddity with Factory Girl

0

80 views

so i had the following associations...

Product
  embeds_many :pressings
Pressing
  embedded_in :product
  embeds_many :variations
Variation
  embedded_in :pressing

after realizing referencing associations would better suit my needs, the associations became...

Product
  references_many :pressings
Pressing
  referenced_in :product
  references_many :variations
Variation
  referenced_in :pressing

and now when i run my Factory Girl factories...

Factory.define :product do |product|
  product.after_create    { |p| 5.times { Factory(:pressing, :product => p) } }
end
Factory.define :pressing do |pressing|
  pressing.after_create   { |p| 5.times { Factory(:variation, :pressing => p) } }
end
Factory.define :variation do |variation|
end

the products and pressings are associated together properly, but the pressings and variations are not, even though the variations are being created. the oddity can be seen in the following commands...

>> v = ProductVariation.first
=> #<ProductVariation _id: 4d9acc89e1607c48fd00001c, _id: BSON::ObjectId('4d9acc89e1607c48fd00001c'), _type: nil, pressing_id: BSON::ObjectId('4d9acc89e1607c48fd00001b')>
>> v.pressing.product.pressings.first.variations
=> []

you can see that i start with an existing pressing... work my way up to the product, and then back down to view all variations... but the count is 0. how can this be?

asked April 5, 2011 3:19 am CDT
posted via StackOverflow

1 Answers

0
 

so i discovered that removing :class_name solved the problem (i think. still doing testing)

referenced_in :pressing, :class_name => "ProductPressing"

to:

referenced_in :product_pressing

i was using class_name just fine with embedded_in. can it not be used with referenced_in?

answered April 10, 2011 3:04 pm CDT

Your answer

Join with account you already have


Sign in with Twitter account
Sign in with Facebook account
Sign in with Google Friend Connect

Preview
Similar questions