/app/models/reminder.php
<?php class Reminder extends AppModel { var $name = 'Reminder'; } ?>Each reminder "belongs to" a user, and each user can "have many" reminders, so there is a one to many relationship between the two tables. To indicate this to Cake, add the following information below the
$name
variable:
var $belongsTo = array('User');In addition, each reminder has a one to many relationship with drugs, so it "belongs to" a drug. Add
'Drug'
after 'User'
in the above line.
When designing your database, ensure that each model that "belongs to" another model has the appropriate foreign key field. For example since each reminder belongs to a user, that user is identified by the key "user_id" in the
reminder
table. If you stray from convention (classname_id) you have to define the foreign key explicitly in your model.
var $belongsTo => array( 'User' => array( 'foreignKey' => 'UniqueUserID' ) );Upload the file.
No comments:
Post a Comment