Since the with() method in the chain returns a CActiveFinder instead of CActiveRecord, this obviously won’t work. Assuming I don’t want to use direct SQL, what would be the best way to handle this situation? All I can think of is SELECTing all Field_Value records, put their IDs in an array and use that array in a subsequent DELETE query. I hope there is a better way.
This will not work, as findAll() always returns an array, so the deleteAllByAttributes() call will fail. I wondered, why the delete*() methods are not implemented in CActiveFinder. Might be useless for the standard LEFT JOIN but useful for INNER JOIN. But maybe i’m missing something here .
In your situation i think i’d add a method like deleteFieldValues() to your AR and perform deletion in a seperate call.
Our app has an explicit requirement to be as DB independent as can be, so I want to use as little direct SQL as possible. A delete statement will probably remain pretty universal across DBs, but still I prefer to start off as abstract as possible. If it proves to be a serious bottleneck, I could always change it to hard SQL. Fortunately, this operation won’t be executed a lot since it’s mostly used for maintenance by a single admin, but still a nice AR way to handle similar situations would always be appreciated
I see. Not sure, if that’s possible, but maybe you could use CDbCommandBuilder in that method to build your query. That’s exactly what AR does internally. Using CDbCommandBuilder makes sure, that your query will be compatible to your DBMS. You could take a look into db/ar/CActiveRecord.php to see how it’s used by AR. E.g. see the implementation of deleteByPk() or insert().