Miscellaneous
hasOne()
Signature
Section titled “Signature”hasOne() — returns any
Description
Section titled “Description”Sets up a hasOne association between this model and the specified one.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | yes | — | See documentation for belongsTo. |
modelName | string | yes | — | See documentation for belongsTo. |
foreignKey | string | yes | — | See documentation for belongsTo. |
joinKey | string | yes | — | See documentation for belongsTo. |
joinType | string | yes | outer | See documentation for belongsTo. |
dependent | string | yes | false | See documentation for hasMany. |
Examples
Section titled “Examples”// Specify that instances of this model has one profile. (The table for the associated model, not the current, should have the foreign key set on it.)
hasOne("profile");
// Same as above but setting the `joinType` to `inner`, which basically means this model should always have a record in the `profiles` table
hasOne(name="profile", joinType="inner");
// Automatically delete the associated `profile` whenever this object is deleted
hasMany(name="comments", dependent="delete");