situation description:
A Table: user"s coupon Information Table, Field: id,ticket_id,status
B Table: voucher Information Table, Field: id,ticket_info,status
in Model A, there is the following code:
class An extend Model
{
public function getUserTicket ($user_id)
{
$userTicketInfo = $this->field([
"status",
"ticket_id"
])
->where([
"user_id"=>$user_id,
"status"=>0
])
->with([
"B" => function($query) {
$query->field([
"id",
"ticket_info"
]);
}
])
->select();
return $userTicketInfo;
}
public function belongB ()
{
return $this->belongsTo("B","ticket_id","id")->setEagerlyType(0);
}
}
now if you search in this way, you can get the correct result, but if you change setEagerlyType (0) to setEagerlyType (1), it will prompt the question that id and status are not unique. The question to think about is:
1. Is this way of use correct?
2, setEagerlyType (0) use IN mode, changed to setEagerlyType (1) the original meaning is to switch to join mode, but id, status is not the only problem, how to write here?