I'm using cakephp and I want that in my userController.php retrieve data from another table (ingredient_aliases). This is the model of ingredientAlias
class IngredientAlias extends AppModel {
public $name = 'IngredientAlias';
public $useTable = 'ingredient_aliases';
public $belongsTo = array(
'Ingredient' => array(
'className' => 'Ingredient',
'foreignKey' => 'ingredient_id'
)
);
...
I want to retrieve data form the table ingredient_aliases (last 10 created) from my userController.php
I have tried in this mode:
$this->loadModel('IngredientAlias', 2);
$ingg = $this->IngredientAlias->read();
$options['joins'] = array(
array('table' => 'ingredient_aliases',
'alias' => 'ing',
'type' => 'LEFT',
'foreignKey' => 'ing.user_id',
'order' => 'ing.created DESC',
'limit' => 3,
'conditions' => array(
'ing.user_id = User.id'
)
)
);
$options['conditions'] = array( );
$this->set('ingredient',$this->IngredientAlias->find('all', $options));
But this give me this error: Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'User.id' in 'on clause'
Can someone help me? Thanks
You can simply instantiate another model (table) on any controller or component by using the following.
$data = ClassRegistry::init('IngredientAlias')->find('first', array());
That's it. You will be able to access any data on any table.