getting the sql query from a activerecord call

Hi,

I have to export a lot of products (5000) with a lot of information from all kind of related tables. I have defined the model, relations, etc but if I try to get the products using the simplest method the php is out of memory (it’s not possible to increase php memory … it’s already 256m):

Product::model()->with(‘relation1’, ‘relation2’, … ‘relation3’)->findAll()

Does anyone has any ideas how to get the sql query from Product::model()->with(‘relation1’, ‘relation2’, … ‘relation3’) so I can execute it with createCommand ?

Thanks.

Hello,

Use DAO instead of CActiveRecord. Build simple query with joins and fetch results using DAO (Please go through Working with Database).

I know but if I have all models and their relations it’s more easy to use it to generate a sql command.It’s more readable and usefull for maintenance (db changes). You’ll modify only the model/relation.