Reputation: 6786
class Room
has_many :room_markers
has_many :rooms, through: :room_markers
end
class Marker
...
end
class RoomMarker
belongs_to :room
belongs_to :marker
end
I have a set of classes as mentioned above.
Now I realize that Room
could have has_and_belongs_to_many
association with Maeker
instead of has_many_through
Now my question is "Should I refactor those models? to have has_and_belongs_to_many
association instead of has_many_through
".
Is there any performance related issue if I continue with the existing design?
Upvotes: 1
Views: 368
Reputation: 244
Simpler is better. You should refactor if you don't need the extra model.
The simplest rule of thumb is that you should set up a has_many :through relationship if you need to work with the relationship model as an independent entity. If you don't need to do anything with the relationship model, it may be simpler to set up a has_and_belongs_to_many relationship (though you'll need to remember to create the joining table in the database).
From the guides.
I don't think you have to worry about performance at this level, just take the solution that fits your needs.
Upvotes: 1