S
S
Smilez Gray2016-02-08 01:46:43
Ruby on Rails
Smilez Gray, 2016-02-08 01:46:43

What type of model relationship should be used instead of belongs_to, to indicate belonging to several model objects?

Two models:
project authors (author) and projects (project).
The authors have several projects:

class Author < ActiveRecord::Base
  has_many :projects
end

feedback (projects belong to the authors):
class Project < ActiveRecord::Base
  belongs_to :author
end

However, some projects were written jointly by several authors, so belongs_to is not appropriate, and instead of the "projects" table it looks like:
integer :id
string  :name
integer :author_id

something like:
integer  :id
string   :name
array    :author_ids

What type of relationship is suitable for this option instead of belongs_to?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Beloshitsky, 2016-02-08
@Smilez-Grey

Try using HATBM
This will require an additional plateauthors_projects

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question