Reputation: 1340
I have a column called operators which is a json array that looks like this [1, 2, 3]
. The numbers are ids on the operators table. Now how can I use the HasJsonRelationships to get the operators. I have only found one way to use this with objects in an array.
I tried this:
public function operators(): HasManyJson
{
return $this->hasManyJson(Operator::class, 'operators[]');
}
UPDATE:
Tried following
public function operators(): HasManyJson
{
return $this->hasManyJson(Operator::class, 'operators[]->id');
}
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'operators.operators' in 'where clause'
select * from `operators` where (1 member of(json_extract(`operators`.`operators`, '$[*]."id"')))
and
public function operators(): HasManyJson
{
return $this->hasManyJson(Operator::class, 'operators');
}
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'operators.operators' in 'where clause'
select * from `operators` where (1 member of(`operators`.`operators`))
Upvotes: 0
Views: 36