activerecord - rails models: can be foreign key null? -


i have event table , place table. events belongs places, while others don't. decided create table: placed_event = events belongs place. question is: should keep way or have placed_event table , delete events table, placed_events have foreign key null - i.e. not belong place?

the answer "it depends."

if events can in 0 or 1 places, having events table foreign key places table work fine; mohammad said in comment, if place_id null, event doesn't have place.

if events can spread across more 1 place, concert many stages, that's when having join table make sense.

hope helps.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -