Tal
Tal

Reputation: 1448

Change name of mongoid relations (embeds_...,belongs_to,has_...)

When you have a relation such as embeds_many :album_items which relates to the AlbumItem model. How can I have it stored in just items. I tried embeds_many :album_items, :as => :items and embeds_many :items, :class_name => AlbumItem. Neither worked.

How can I go about renaming the relation?

Thanks

Upvotes: 3

Views: 1709

Answers (1)

James Chen
James Chen

Reputation: 10874

Does this work(assuming your parent model name is Album)?

In Album:

embeds_many :items, :class_name => "AlbumItem", :inverse_of => :album

and in AlbumItem:

embedded_in :album, :class_name => "Album", :inverse_of => :items

Upvotes: 7

Related Questions