Closed gabrielkoerich closed 4 years ago
@gabrielkoerich This completely makes sense. Good catch. However, it is possible that the value is not a model, and therefore it wouldn't have an accurate id. The id is needed for other field types and whatnot. Here is our suggestion for the fix:
if ($this->value instanceof Model) {
$models = [$this->value->id];
} elseif ($this->value instanceof Collection) {
$models = $this->value->pluck('id')->all();
}
$this->withMeta([
...
'models' => $models ?? [],
...
]);
What are your thoughts on it?
We merged code in that fixes this issue in #32 in a more robust way plus resolved a secondary issue from #13. Thanks so much for the PR!
Not sure if this is intended, but if
$this->value
is aModel
instance, thepluck
method will return all ids from the database, which is really slow here (>1M records).