SQL Builder With PDO, ORM etc
$model->option_items
不会调用 $model->optionItems()
$query->isEmpty();
$model = new Model();
$model->setRaelation('a', 122222);
empty($model['a']) // true
$model->relationLoaded('a') // true
根据商品获取商品属性及属性名,
$data = [
'id' => 1,
'name' => 2
];
$data = Relation::create($data, [
't' => [
'query' => GoodsAttributeModel::query(),
'link' => ['id', 'goods_id'],
'relation' => [
'attr' => [
'query' => AttributeModel::query(),
'type' => 0,
'link' => ['attribute_id', 'id'],
]
]
],
]);
最终结果如下
{
"id": 1,
"name": 2,
"t": [
{
"id": 10000,
"goods_id": 1,
"value": "11111",
"attribute_id": 5,
"attr": {
"id": 5,
"name": "尺寸"
}
}
]
}
多级如果关联名为空则替换上一级,例如
$data = [
'id' => 1,
'name' => 2
];
$data = Relation::create($data, [
't' => [
'query' => GoodsAttributeModel::query(),
'link' => ['id', 'goods_id'],
'relation' => [
[
'query' => AttributeModel::query(),
'type' => 0,
'link' => ['attribute_id', 'id'],
]
]
],
]);
最终结果如下
{
"id": 1,
"name": 2,
"t": [
{
"id": 5,
"name": "尺寸"
}
]
}