我正在使用多个两个名为'default'和'default_history的数据库。在“默认”数据库下,我有一个名为“食谱”的表,在“默认历史”数据库下有一个“ order_detail_history”。我有名称为OrderDetailHistoryTable的模型表。这是我的模型表:-
public static function defaultConnectionName()
{
return 'default_history';
}
public function initialize(array $config)
{
parent::initialize($config);
$this->setTable('order_detail_history');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->belongsTo('RecipesLeft', [
'strategy' => 'select',
'propertyName' => 'Recipes',
'className' => 'Recipes',
'foreignKey' => 'recipe_id',
'joinType' => 'LEFT'
]);
}
我正在使用查询:-
$recipe_list_history = $this->OrderDetailHistory->find('list', ['keyField' => 'RecipesLeft.id', 'valueField' => 'RecipesLeft.recipe_name'])->select(['RecipesLeft.id', 'RecipesLeft.recipe_name'])->contain(['RecipesLeft'])->where(['OrderDetailHistory.order_id' => $history_id])->order(['OrderDetailHistory.id'])->hydrate(false)->toArray();
并且我收到此数据库错误:-
Column not found: 1054 Unknown column 'RecipesLeft.id' in 'field list'
SELECT RecipesLeft.id AS `RecipesLeft__id`, RecipesLeft.recipe_name AS `RecipesLeft__recipe_name` FROM order_detail_history OrderDetailHistory WHERE OrderDetailHistory.order_id = :c0 ORDER BY OrderDetailHistory.id
我在模型表中定义了关联,但是我无法通过order_detials_history加入配方表。!
答案 0 :(得分:0)
您的食谱表似乎没有id列(主键)。您可以发布三个表的数据库方案吗?