Skip to content

Mappable + Multiple Wheres #266

Open
@gfernandez-me

Description

@gfernandez-me

When you try to use mappable and logical grouping the mappable fields won't work.

https://laravel.com/docs/8.x/queries#logical-grouping

class MyModel {
  use Eloquence, Mappable;
 protected $maps = [
        'id'               => 'myId',
        'field1'         => 'myField1',
        'field2'         => 'myField2',
        'is_enabled' => 'enabled'
    ];

}
$this->queryBuilder = MyModel::query();
$this->queryBuilder->where('is_enabled', 1);
$this->queryBuilder->where(function ($query) use ($searchCriteria) {
                $text = '%'.Arr::pull($searchCriteria, 'text').'%';
                return $query->where('field1', 'LIKE', $text)
                ->orWhere('field2', 'LIKE', $text);
});
$this->queryBuilder->get();

Error:
SQLSTATE[42S22]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid column name 'field1'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions