KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
This question is about the naming style of polymorphic relationships. My database has three types of person: a 'Company', a Client, and an Employee. Each of the three are in polymorphic relationships with tasks and events, and projects. According to the Rails guides, this would be done like (I've omitted some classes for brevity): Person.rb has_many :tasks, :as => :taskable has_many :events, :as => :eventable has_many :projects, :as => :projectable # awkward names Task.rb belongs_to :taskable, :polymorphic => true These lead to the rather strange: @person = @task.taskable I feel that the following would be far more grammatical and elegant... would it work, and if so, is there a reason that official sources use words like projectable rather than words like owner ? Person.rb has_many :tasks, :as => :owner has_many :events, :as => :owner has_many :projects, :as => :owner Task.rb belongs_to :owner, :polymorphic => true This creates the elegant: @person_1 = @task.owner @person_2 = @project.owner
Tags (comma-separated)
Save Edits
Cancel