php - Pass foreign key from controller to model for specific query cakephp 2.3.9 -
i want use 2 different foreign key 2 different query
for first query want like:
my model code
public $belongsto = array( 'emailformatstype' => array( 'classname' => 'emailformatstype', 'foreignkey' => 'id' ) );
now second query want like:
my model code
public $belongsto = array( 'emailformatstype' => array( 'classname' => 'emailformatstype', 'foreignkey' => 'new_id' ) );
so question is there technique can pass foreignkey controller specific query
something provide recursive
$this->model->recursive = 0;
same want like:
$this->model->foreignkey= 'my_foreignkey';
simply access associations property:
$this->model->belongsto['yourassoc']['foreignkey'] = 'my_foreignkey';
some best practice: emailformatstype bad name, should emailformattype. reads better , matches convention. notice plural had before (formats) make join table convention.
Comments
Post a Comment