开发者

MongoDB object / association oddity

开发者 https://www.devze.com 2023-02-21 22:23 出处:网络
so i had the following associations... Product embeds_many :pressings, :class_name => \"ProductPressing\"

so i had the following associations...

Product
  embeds_many :pressings, :class_name => "ProductPressing"
ProductPressing
  embedded_in :product
  embeds_many :variations, :class_name => "ProductVariation"
ProductVariation
  embedded_in :pressing, :class_name => "ProductPressing"

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

Product
  references_many :pressings, :class_name => "ProductPressing"
ProductPressing
  referenced_in :product
  references_many :variations, :class_name => "ProductVariation"
ProductVariation
  referenced_in :pressing, :class_name => "ProductPressing"

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:开发者_如何学C 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?


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消