Skip to content

Miscellaneous

hasOne()

hasOne() — returns any

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

NameTypeRequiredDefaultDescription
namestringyesSee documentation for belongsTo.
modelNamestringyesSee documentation for belongsTo.
foreignKeystringyesSee documentation for belongsTo.
joinKeystringyesSee documentation for belongsTo.
joinTypestringyesouterSee documentation for belongsTo.
dependentstringyesfalseSee documentation for hasMany.
// 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");