Skip to content

Model Configuration

hasMany()

hasMany() — returns void

Available in: model Category: Association Functions

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

NameTypeRequiredDefaultDescription
namestringyesGives the association a name that you refer to when working with the association (in the include argument to findAll, to name one example).
modelNamestringnoName of associated model (usually not needed if you follow Wheels conventions because the model name will be deduced from the name argument).
foreignKeystringnoForeign key property name (usually not needed if you follow Wheels conventions since the foreign key name will be deduced from the name argument).
joinKeystringnoColumn name to join to if not the primary key (usually not needed if you follow Wheels conventions since the join key will be the table’s primary key/keys).
joinTypestringnoouterUse to set the join type when joining associated tables. Possible values are inner (for INNER JOIN) and outer (for LEFT OUTER JOIN).
dependentstringnofalseDefines how to handle dependent model objects when you delete an object from this model. delete / deleteAll deletes the record(s) (deleteAll bypasses object instantiation). remove / removeAll sets the forein key field(s) to NULL (removeAll bypasses object instantiation).
shortcutstringnoSet this argument to create an additional dynamic method that gets the object(s) from the other side of a many-to-many association.
throughstringno[runtime expression]Set this argument if you need to override Wheels conventions when using the shortcut argument. Accepts a list of two association names representing the chain from the opposite side of the many-to-many relationship to this model.
asstringno