Back
belongsTo()
1. Standard belongsTo association
// Specify that instances of this model belong to an author
belongsTo("author");
Wheels will automatically deduce the foreign key as authorId and the associated model as Author.
2. Custom foreign key and model name
// Foreign key does not follow convention
belongsTo(name = "bookWriter", modelName = "author", foreignKey = "authorId");
Useful when your database column names or model names deviate from Wheels conventions.
3. Specify LEFT OUTER JOIN
belongsTo(name = "publisher", joinType = "outer");
Copied!