Answer the question
In order to leave comments, you need to log in
How to make a relation without related tables?
Good afternoon, I have a relation in the Items model:
public function getPlan()
{
return $this->hasOne(Plans::className(), ['id' => 'value'])
->viaTable(ItemsPropsValues::tableName(), ['item_id' => 'id'], function ($query) {
/** @var ActiveQuery $query */
$query->where(['type_id' => $this->category->itemsPropsTypes['plan_id']->id]);
});
}
Answer the question
In order to leave comments, you need to log in
The structure is something like this:
Items (id, category_id)
ItemsPropsTypes(id, category_id)
ItemsPropsValues(item_id, type_id, value)
Plans(id)
I need to get the Plans object whose id is stored in the ItemsPropsValues table in the value attribute, with the condition that type_id == 4.
This connection is necessary in the Items model, you can get it by FK Items_id- ItemsPropsValues_item_id.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question