Return to v1.4.5 docs

hasOne()



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

Name Type Required Default Description
name string Yes See documentation for belongsTo.
modelName string No See documentation for belongsTo.
foreignKey string No See documentation for belongsTo.
joinKey string No See documentation for belongsTo.
joinType string No outer See documentation for belongsTo.
dependent string No false See 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");