Closed sfadschm closed 3 years ago
Or maybe just change the readme :)
You are correct. Maybe something like the handling above that?
// Force a single table name into an array
if (! is_array($with))
{
$with = [$with];
}
Yeah this looks much better than just casting or extending the one-liner.
On second thought:
If $with
is null
, then is_array
returns false too and will generate [null]
instead of []
with are unequal according to var_dump
at least. Does this matter?
Yes sorry, that was pasted from ModelTrait. I'm on mobile, writing code is hard.
Basically getWith()
should always return string[]
, so either []
or an array of strings.
I won't be on desktop for another 12 hours or so but feel free to send a PR if you want to fix this.
The readme states, that the ModelTrait can be used as follows:
When using the first option and using a string for a single relation,
ModelTrait->getWith
throws an error because it is supposed to return an array:https://github.com/tattersoftware/codeigniter4-relations/blob/b964ae2410da9b93c14167b2d396d1768cec9572/src/Traits/ModelTrait.php#L83-L87
Should
$this->with
be casted to array maybe?