Answer the question
In order to leave comments, you need to log in
How to create a filter using hasMany and hasOne?
There are, for example, such linking tables with Ticket
public function getGroup()
{
return $this->hasOne(Group::className(), ['id' => 'group_id'])
->viaTable('{{%group_ticket}}', ['ticket_id'=>'id'])->where(['id'=>
GroupTicket::find()->select('group_id')->where(['id'=>
GroupTicket::find()->select('max(id)')->groupBy('ticket_id')
])
]);
}
public function getGroupTickets()
{
return $this->hasMany(GroupTicket::className(), ['ticket_id' => 'id']);
}
Answer the question
In order to leave comments, you need to log in
$query = Ticket::find()->joinWith(['group', 'groupTickets']);
$query->where([
'group.name' => $groupName,
'groupTickets.name' => $ticketName,
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question