Showing posts with label hasMany. Show all posts
Showing posts with label hasMany. Show all posts

Wednesday, November 3, 2010

Update Model: Drug

As mentioned previously, to coordinate with the reminder model, add the relationship to the drug model. Edit /app/models/drug.php and add
    var $hasMany = array('Reminder');
Save and upload the file.

Update Model: Carrier

As mentioned previously, to coordinate with the user model, add the relationship to the carrier model. Edit /app/models/carrier.php and add
    var $hasMany = array('User');
Upload the file.

Update Model: User

As mentioned previously, to coordinate with the reminder model, add the relationship to the user model. In addition while each carrier can have many users, each user belongs to a carrier so indicate that as follows as well:

Edit /app/models/user.php and add
    var $hasMany = array('Reminder');
    var $belongsTo = array('Carrier');
Upload the file.

Like when a model belongs to another model, if the foreign key is not standard you need to explicitly define it. You can also explicitly define the class name if that isn't the default also.
    var $hasMany=> array(
        'Reminder' => array(
            'className' => 'Reminder',
            'foreignKey' => 'UniqueUserID'
        )
    );