When using ActiveRecord::find(), I was expecting Yii would automatically add ‘limit’=>1 to the criteria.
Is there any reason not to do this?
When using ActiveRecord::find(), I was expecting Yii would automatically add ‘limit’=>1 to the criteria.
Is there any reason not to do this?
If you want to have more records then use findAll()
It does or at least it should, according to the code here : CActiveRecord
According to that code snipplet, the limit is only applied when the supplied criteria doesn’t contain any joins (with).
So my question becomes more specific: Is there a reason not to automatically set limit when using joins? (might we not always get the expected results?)
Yes, because the limit will be applied to the joins as well, so you will only ever get one row back which will break HAS_MANY and MANY_MANY relations.