ruby on rails 3 - ActiveRecord Associations: Any gotchas if has_many WITHOUT corresponding belongs_to? -


a phone has many messages.

an email address has many messages.

a message either belongs phone, email, or neither. belongs_to association optional.

the following associations seem work fine these relationships:

  • phone model has_many :messages
  • email model has_many :messages
  • message model not have belongs_to :phones, :email

is okay or there proper way specify "can_belong_to" relationship?

it correct unidirectional relation. using both called "curcular dependency" purists , may cause problems when using validates_associated.

from other side using has_many :messages may not enough when want retrieve phone information 1 message. matter of convenience.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -