How to create aliases for associations #5593
Unanswered
valentinfp
asked this question in
Q&A
Replies: 1 comment
-
Hi @valentinfp, you could do this using a custom association name similar to the following: class TestQuestion
include Mongoid::Document
field :title, type: String
belongs_to :test
end
class Test
include Mongoid::Document
field :title, type: String
has_many :questions, class_name: "TestQuestion"
end |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Let's say I'm working a generic class like
What's the best way I can make an alias named
questions
for thattest_questions
association? I first tried usingalias_attribute
, but it doesn't work for associations because it tries to create alias for methods that don't exist, liketest_questions_change
, and raises an error.Beta Was this translation helpful? Give feedback.
All reactions