1

私はcakephpを使用していますが、userController.phpで別のテーブル(ingredient_aliases)からデータを取得する必要があります。これはcomponentAliasのモデルです

class IngredientAlias extends AppModel {
    public $name = 'IngredientAlias';
    public $useTable = 'ingredient_aliases';
    public $belongsTo = array(
        'Ingredient' => array(
            'className'    => 'Ingredient',
            'foreignKey'   => 'ingredient_id'
        )
    );
...

userController.phpからテーブルcomponent_aliases(最後に作成された10個)からデータを取得したい

私はこのモードで試しました:

$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));

しかし、これは私にこのエラーを与えます:エラー:SQLSTATE [42S22]:列が見つかりません:1054不明な列'User.id' in'onclause'

誰かが私を助けることができますか?ありがとう

4

1 に答える 1

9

以下を使用して、任意のコントローラーまたはコンポーネントで別のモデル (テーブル) を簡単にインスタンス化できます。

$data = ClassRegistry::init('IngredientAlias')->find('first', array());

それでおしまい。どのテーブルのどのデータにもアクセスできます。

于 2012-07-02T04:54:59.667 に答える