?– Note Inner joinsreturn only records that have a match in both tables (we would not get results if we tried
to find a cow that didn??™t have an owner). Left joinsreturn all the records from the left table, even if there is no
matching record in the right table (in this case, we would get the cow information even though it belonged to
no farmer). Inner joins are generally denoted by the use of the keyword AND in their plain English representation.
has_many
On the other end of belongs_to, there is has_many. It??™s pretty easy to think of where this can be
applied: A farmer owns many cows. A blog has many posts, which may have many comments.
A customer has many orders, each of which has many products, and a product has many images.
A site has many pages. We could go on all day.
This association, like has_one, does not keep track of its own foreign key (looking at our
farmer table, you see that there are no foreign keys defined within that table). This means that
any number of other objects can be associated with this one, and the database can still keep
a normalized form (that is, without excess duplication of data).
Pages:
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192