Welcome Guest, Not a member yet? Register   Sign In
Quick datamapper query question
#1

[eluser]Andy78[/eluser]
I want to get all users that have a user_type_id of 1 or 2 and their user_status does not equal 'deleted'.

Currently I have:

Code:
$admin_users = new User();
        $admin_users->where('user_status !=', 'deleted');
        $admin_users->where('user_type_id', 1);
        $admin_users->or_where('user_type_id', 2);
        $admin_users->include_related('user_type', array('user_type'), TRUE, TRUE);

This is returning all users where user_status != 'deleted' AND where user_type_id = 1 OR where user_type_id = 2.


Which clearly is not correct because any user with an user_type_id of 2 is returned.

How do I perform this query correctly in datamapper?
#2

[eluser]WanWizard[/eluser]
This is clearly correct, given the question you have asked.

But maybe you're asking the wrong question, and do you mean: user_status != ‘deleted’ AND (user_type_id = 1 OR user_type_id = 2).

Datamapper can't guess that you want (or need) brackets in there, so you'll have to add them. Look in the manual for query grouping...
#3

[eluser]Andy78[/eluser]
[quote author="WanWizard" date="1332438286"]This is clearly correct, given the question you have asked.

But maybe you're asking the wrong question, and do you mean: user_status != ‘deleted’ AND (user_type_id = 1 OR user_type_id = 2).

Datamapper can't guess that you want (or need) brackets in there, so you'll have to add them. Look in the manual for query grouping...[/quote]

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB