When to choose between has_and_belongs_to_many and has_many, through association
This was really confusing for me when to choose has_and_belongs_to_many and when to choose has_many , through association because both sets up many-to-many relationship between tables. Qns: When to choose has_and_belongs_to_many association . Ans: The answer is when we does not need any kind of information about the association or the information about join model then we should use has_and_belongs_to_many association. Example: An assembly can have many parts and a part can have many assemblies and we don't need any other information about association then sets up direct many-to-many association between tables. via another table called assemblies_parts and it should have the foreign keys for both the table. Qns: When to choose has_many, through association. Ans: The answer is when we need the information about the association or the information about join model then we should use has_many ,through association. Example: A physician can have many