Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

Where condition = 0

edited January 2014 in Framework

The products table has 955 items, 2 featured.

$products = Product::query ()->where('featured', 1)->fetch() ;
info (DB::$last_sql);
info (DB::$last_args);
echo count($products);

works as expected and produces

select * from `products` where `featured` = ?
Array
(
    [0] => 1
)
2

But

$products = Product::query ()->where('featured', 0)->fetch() ;

produces

select * from `products` where featured
Array
(
)
2

I can use ->where('featured = 0') and then I get the expected 953 results:

select * from `products` where featured = 0
Array
(
)
953

The problem is I'm building the query dynamically and don't know if $featured is 0 or 1. I can test for it, of course, but I'm wondering if this is the expected behavior?

Comments

  • This is an issue. Looks like I was using $val = false which 0 evaluates to, so I've updated it to explicitly use $val = null and test for null instead (e.g., the right way ;). Fix is in master on Github now.

  • Thank you!

Sign In or Register to comment.