You are viewing documentation for v1.0.x. Change

belongsTo()

Description

Sets up a belongsTo association between this model and the specified one.

Function Syntax

belongsTo(name [, class, foreignKey, joinType ])

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 inner Use to set the join type when joining associated tables, possible values are inner (for INNER JOIN) and outer (for LEFT OUTER JOIN).

Examples

<!--- Specify that instances of this model belongs to an author (the table for this model should have a foreign key set on it, typically named `authorid`) --->
<cfset belongsTo("author")>

<!--- Same as above but since we give the association a different name we have to set `class` and `foreignKey` since Wheels won't be able to figure it out based on the association name anymore --->
<cfset belongsTo(name="bookWriter", class="author", foreignKey="authorId")>