Created
February 2, 2014 21:36
-
-
Save abfan1127/8775304 to your computer and use it in GitHub Desktop.
Laravel Eloquent whereHas Escapes numeric breaking sqlite count(...) > ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function getFeaturedProducts_DOESNTWORK_WITH_SQLITE($storeId, $limit = 1) | |
{ | |
$query = $this->product->newInstance() | |
->where('store_id', $storeId) | |
->limit($limit) | |
->with( | |
array( | |
'productMedia' => function ($query) { | |
/** | |
* we can't limit it because it gets all of the media at once | |
*/ | |
$query->orderBy('mediaType','asc'); | |
} | |
) | |
); | |
$query->whereHas('productAttribute',function ($query) { | |
return $query->where('attributeKey', 'featured') | |
->where('attributeValue', 'true'); | |
},'>=',1); // <- this is an integer of 1. | |
$results = $query->get(); | |
return $results; | |
} | |
public function getFeaturedProducts_WORKS_WITH_SQLLITE($storeId, $limit = 1) | |
{ | |
$query = $this->product->newInstance() | |
->where('store_id', $storeId) | |
->limit($limit) | |
->with( | |
array( | |
'productMedia' => function ($query) { | |
/** | |
* we can't limit it because it gets all of the media at once | |
*/ | |
$query->orderBy('mediaType','asc'); | |
} | |
) | |
); | |
$query->whereHas('productAttribute',function ($query) { | |
return $query->where('attributeKey', 'featured') | |
->where('attributeValue', 'true'); | |
},'>=', DB::raw('1')); // this works | |
$results = $query->get(); | |
return $results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment