I have a huge DB, and I was using findByAttributes() to get the first record of an ordered set, with a joined table. It started failing with a fatal error that I’d maxed out my memory… The fix was to manually add LIMIT 1 to my custom scope.
Seems like it was trying to select 20,000+ rows, join another table, sort the rows, pull them all back into PHP, then just return the first one. Am I correct in understanding that findByAttributes() et al. doesn’t automatically use LIMIT 1? Is there a reason for this?
From looking at the code behind the CActiveRecord::query() method, it seems that the limit condition is added as long as there is no with clause (so there are no joins).
Perhaps this is because adding a limit clause is too naïve an approach when complex joins are involved, but I can’t immediately see why that would be.
EDIT:
It could of course be a bug. Would you like me to move this thread into the bug discussion forum?