findByAttributes vs find

Hi,

I was wondering if it makes any difference to use either of these functions, are there any advantages of using one over the other.

Example if I have a field called id_category, I can use findByAttributes to match all records by that field or the condition parameter.

In what scenario would you use one over the other?

I’m just trying to understand the difference.

Thanks!

Hmm, I think they’re basically the same, you just specify the criteria differently.

‘find()’ returns a single row, the first row that matches the criteria.

‘findByAttributes’ also returns a single row matching the criteria.

Perhaps ‘findByAttributes’ is a little faster since you don’t instantiate the CDbCriteria object, but I’m not sure how they work internally.

findByAttributes just saves you time because you don’t have to write sql and the parameters are automatically bound. Though you can add additional sql as the second parameter and the params for that sql as the third parameter.