Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Assigning alias to a model

Let's say I have a model class inside MyApp\Models namespace. Now when I want to filter my data on some specific column, I have to do someting like the following:

MyApp\Models\Customer::find("MyApp\Models\ = 'Some cool name'");

Is there some way to avoid typing "MyApp\Models\" and just use some table alias, so that I could just put "" instead?

Only name must work:

MyApp\Models\Customer::find("name = 'Some cool name'");

Yeah, it does. But what if the column is ambiguous, in case the table is joined with another table. The following will not work because I would have to specify "MyApp\Models\ = 123" instead of "id = 123":

        ->join('MyApp\Models\Company',  ' = MyApp\Models\Customer.company_id', 'c')
        ->where('id = 123')

edited May '15

You can use the query builder instead:

$robots = $this->modelsManager->createBuilder()
    ->from(['r' => 'Some\Robots'])
    ->where(' = "Ultron"')

That was what I was looking for. Thanks :)