Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error #2

Open
rudy-on-rails opened this issue Nov 5, 2012 · 0 comments
Open

Error #2

rudy-on-rails opened this issue Nov 5, 2012 · 0 comments
Labels

Comments

@rudy-on-rails
Copy link
Owner

Whenever you have an association with a name that doesn't match associated class name, act_as_a_list_mongoid will try to use the 'associated class pluralized and underscoralized name' when one of its methods is invoked, raising a "NoMethodError" exception.

Example:

class Commit
   include Mongoid::Document
   embeds_many :properties, class_name: 'CommitProperty'
end

class CommitProperty
   include Mongoid::Document
   include ActsAsList::Mongoid
   embedded_in :commit, class_name: 'Commit', inverse_of: :properties
end

Calling commit.init_list! will raise the error.

Workaround:

add an alias to match relation name. In above's case,

class Commit
   include Mongoid::Document
   embeds_many :properties, class_name: 'CommitProperty'
   alias :commit_properties :properties
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant