hasMany()
Description
Sets up a hasMany association between this model and the specified one.
Function Syntax
hasMany(name [, class, foreignKey, joinType, shortcut, through ])
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
name |
string |
Yes | |
Gives the association a name that you refer to when working with the association (in the include argument to findAll() to name one example). |
class |
string |
No | |
Name of associated class (usually not needed if you follow the Wheels conventions since the model name will be deduced from the name argument). |
foreignKey |
string |
No | |
Foreign key property name (usually not needed if you follow the Wheels conventions since the foreign key name will be deduced from the name argument). |
joinType |
string |
No | outer |
Use to set the join type when joining associated tables, possible values are inner (for INNER JOIN) and outer (for LEFT OUTER JOIN). |
shortcut |
string |
No | |
Set this argument to create an additional dynamic method that gets the objects for a many-to-many association. |
through |
string |
No | [runtime expression] |
Set this argument if you need to override the Wheels convention when using the shortcut argument. |
Examples
<!--- Specify that instances of this model has many comments (the table for the associated model, not the current, should have the foreign key set on it) --->
<cfset hasMany("comments")>
<!--- Specify that this model (let's call it `reader` in this case) has many subscriptions and setup a shortcut to the `magazine` model (useful when dealing with many to many relationships) --->
<cfset hasMany(name="subscriptions", shortcut="magazines")>
