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

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -