it is possible to do like this:
$users = Entry::find()
->userLevel('>3')
->or group('admin')
So in database level,the sql will go like this:
select * from users
where users.userLevel > 3 or users.group='admin'
Many many thanks!!
Yes but not like you tried it. You have to work on Yii2 level and not with Crafts Query
// prefix for content column tables
// if you want to select fields in the field layout do
// $prefix . 'fieldHandle'
$prefix = Craft::$app->getContent()->contentTable . '.' . Craft::$app->getFields()->oldFieldColumnPrefix;
$user = User::find()
->andWhere(
new OrCondition(
['>','users.userLevel', 3],
['=', 'users.group', 'admin']
)
)
->all();
However: keep in mind this SQL will likely produce errors because there is neither a users.group
column nor a users.userLevel
column in the database
Just as an example for more complex search:
$prefix = Craft::$app->getContent()->contentTable . '.' . Craft::$app->getFields()->oldFieldColumnPrefix;
$criteria = [
'where' => new OrCondition(
[
[
'between',
$prefix . 'startDate',
Db::prepareDateForDb($startDateDb),
Db::prepareDateForDb($endDate)
],
new AndCondition(
[
['=', $prefix . 'recurring', 1],
['<=', $prefix . 'startDate', $startDateDb->format('Y-m-d H:i:s')]
]
)
]
),
'orderBy' => ['startDate' => SORT_ASC],
'sectionId' => 10,
];
$query = Entry::find();
\Craft::configure($query, $criteria);
relation
table and check if a value exists with your criteria. You can perform a simple query to see what Craft does. Entry::find()->relatedTo(1)->getRawSql()
Commented
May 3, 2018 at 23:04