-
Notifications
You must be signed in to change notification settings - Fork 19
references
Troy Murray edited this page Sep 15, 2011
·
1 revision
Adds column definition to the table definition object for an association column (belongsTo, hasOne, hasMany) using the CFWheels conventions. Optionally adds a foreign key constraint.
t.references(referenceNames[,default,null,polymorphic,foreignKey]);
Parameter | Type | Required | Default | Description |
referenceNames | string | Yes | one or more reference names (singular of referenced tables, eg. user), comma delimited | |
default | string | No | NULL | default value for column |
null | boolean | No | True | whether nulls are allowed |
polymorphic | boolean | No | False | whether or not to create an Id/Type pair of columns for a polymorphic relationship |
foreignKey | boolean | No | False | whether or not to create a foreign key constraint, ignored if polymorphic set to True |
t.references('user');
will create a column called userid and a foreign key constraint to the id field in the users table.
t.references(referenceNames='user',foreignKey=false);
will create a column called userid without creating a foreign key constraint.
t.references(referenceNames='contact',polymorphic=true);
will create a columns for a polymorphic relationship called contactid and contacttype. You could make use of this in CFWheels by making the contacttype refer to a model name, then using model(this.contacttype).findByKey(this.contactid).
Prior to version 0.4, the convention used for column names was camelCase (e.g. contentId and contentType)