hasOne
relationship is a "one-to-one" relationship. For instance, a User
entity might have an UserProfile
entity attached to it.hasOne
is a WireBox mapping to the related entity.UserProfile
entity is assumed to have a userId
foreign key. You can override this by passing a foreign key in as the second argument:id
as its primary key, or you wish to join the child entity to a different column, you may pass a third argument to the hasOne
method specifying your parent table's custom key.hasOne
is belongsTo
. It is important to choose the right relationship for your database structure. hasOne
assumes that the related model has the foreign key for the relationship.HasOne
relationships can be configured to return a default entity if no entity is found. This is done by calling withDefault
on the relationship object.withDefault
.true
false
entityName() & keyNames()
false
keyNames()
false
relationName
.