I want to display the students added, how to do this and I want to save all the students into database table students
. And one more table called order which has relation with the the student domain class as below
class Order extends AppModel {
var $name="Ord开发者_JAVA百科er";
var $belongsTo = array(
'Student' => array(
'className' =>'Student',
'foreignKey' => 'StudentId'
)
);
}
class Student extends AppModel {
var $name='Student';
var $hasOne = array(
'Order' => array(
'className' => 'Order',
'foreignKey' => 'StudentId'
)
);
}
and I have created relation in database that foreign key studentId
of order table references Id
column of Student
table. So now how to save both associated models?
you must pass a correct formatted data to save
method of your model.
data format is something like
$data = array('Modelname' => array(
'col1'=>'val1',
'col1'=>'val2' )
);
精彩评论