Simulating a belongs_to_many in rails
Posted
by DavidP6
on Stack Overflow
See other posts from Stack Overflow
or by DavidP6
Published on 2010-05-09T10:03:58Z
Indexed on
2010/05/09
10:08 UTC
Read the original article
Hit count: 269
ruby-on-rails
|has-and-belongs-to-many
I have a situation where in theory I would need to use a belongs_to_many relationship. I have an Example model and a Sentence model. Each example object has one sentence but these sentences are not necessarily unique. So, for example, I could have two example models that each have one sentence that is the same sentence. I'm not sure how to go about doing this in rails. I tried using has_and_belongs_to_many, but ran into problems. It seems that I only need the belongs_to :many part of that relationship. Ideally it would look something like this, but I know there is no belongs_to :many.
Example has_one :sentence end
Sentence belongs_to_many :examples end
© Stack Overflow or respective owner