Replies: 1 comment 1 reply
-
I've never actually seen that assuming this code is in a controller, or some other space that has access to $uRows = $this->modelsManager->createBuilder()
->addFrom(\My\Models\Users::class, 'user')
->Columns(['user.*', 'bid'=>'B.id']
->leftJoin('My\Models\Books', 'user.id=B.userId', 'B')
->execute();
foreach($uRows as $row) {
echo $row->user->id,':::',$row->bid, PHP_EOL;
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I made the following model.
And I am writing like this
in order to get this result.
It's important to note that readAttribute () should specify a string with a lowercase letter at the beginning of the original namespace.
It feels very confusing to always have to pass the correct namespace-name through lcfirst() before calling readAttribute().
If the model is placed in the global space, it makes sense that the table name and class name are automatically converted, but if it is not, it is difficult to do it without permission.
And I think that everything should not be placed in the global space, but should be placed in a clearly separated namespace.
"My\Models\Users" and "my\Models\Users" probably won't exist at the same time, but I think they have the problem of making namespaces indistinguishable.
If you specify aliases for all in Columns(), readAttribute() becomes unnecessary, but it is very troublesome if there are many columns.
If you can specify a table alias like Join(), you can call it with the specified alias, so you don't have to worry about case, but I think there is no way.
How can I use it with minimal effort and without mistakes?
Is there any way other than writing it carefully?
Beta Was this translation helpful? Give feedback.
All reactions