-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Belongs_to form NoMethodError when association uses different foreign_key #354
Comments
Since we are passing the Or we can try to be a bit more clever and do something like: AuthorLink.reflect_on_association(:link_type).foreign_key
=> :author_link_type_id which right now is not possible, since the field does not know about the |
I would prefer passing the option in the dashboard, but I know that the goal of administrate is to avoid DSL and keeping the |
Any update or monkey patch for this so we can use Administrative? |
@ACPK, @coneybeare I ran in into the same problem I fixed by adding those methods to the ActiveRecord model. Here is something that could work in your case: class AuthorLink < ActiveRecord::Base
# ...
def link_type_id
end
def link_type_id=(id)
self.link_type = AuthorLinkType.find(id)
end
end |
Any update on this? I found a slightly nicer workaround: class Lister < User
belongs_to :company, foreign_key: :organisation_id
alias_attribute :company_id, :organisation_id
end |
@angusfretwell Thank you! |
I think this was fixed with #807. I'm closing, but please reopen if you think differently. |
Setup
Problem
Visiting
/admin/author_links/2/edit
results inThe
NoMethodError
stems fromField::BelongsTo.permitted_attribute
, where you assume a standard association and hardcode_id
accordingly.Solution
There needs to be more intelligence here to detect
foreign_key
variances amongst others. Agreed?The text was updated successfully, but these errors were encountered: