Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mappable + Multiple Wheres #266

Open
gfernandez-me opened this issue Jul 25, 2021 · 2 comments
Open

Mappable + Multiple Wheres #266

gfernandez-me opened this issue Jul 25, 2021 · 2 comments

Comments

@gfernandez-me
Copy link

gfernandez-me commented Jul 25, 2021

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'.

@gfernandez-me
Copy link
Author

If I try to play a bit things are getting worse.

SQLSTATE[42000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Must specify table to select from. (SQL: select top 20 * from my_model where [enabled] = 1 and (select * where [field1] LIKE %asse% or [field2] LIKE %asse%) is null)

@terry197913
Copy link

code
$productModelCollects = ProductModel
::where
(
function($query) use ($prefix)
{
foreach( $prefix as $i => $v )
{
$query->orWhere("prod_name", "like", "{$v}%");
}
}
)
->whereIn("prod_id", ["1"])
->get();

error
Illuminate\Database\QueryException
SQLSTATE[HY000]: General error: 1096 No tables used (SQL: select * from product where (select * where prod_name like 衣服% or prod_name like 禮物%) is null and prod_id in (1) and product.deleted_at is null)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants