Question

I want to use two different foreign key for two different query

For my first query I want like:

my model code is like

public $belongsTo = array(
    'Emailformatstype' => array(
        'className' => 'Emailformatstype',
        'foreignKey' => 'id'
    )
);

now for my second query I want like:

my model code is like

public $belongsTo = array(
    'Emailformatstype' => array(
        'className' => 'Emailformatstype',
        'foreignKey' => 'New_id'
    )
);

So my question is is there any technique so I can pass foreignKey from controller for specific query

something like as we provide recursive

$this->Model->recursive = 0;

same I want like:

$this->Model->foreignKey= 'My_foreignKey';
Was it helpful?

Solution

Simply access the associations property:

$this->Model->belongsTo['YourAssoc']['foreignKey'] = 'my_foreignKey';

Some best practice: Emailformatstype is a bad name, this should be EmailFormatType. Reads better and matches the convention. Notice the plural you had before (formats) which would make it a join table by convention.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top