Possible Bug in CActiveRecord with() or is it me????

I am querying a MANY_MANY Relation:

Relational Rule:

return array('persons'=>array(self::MANY_MANY,'person','PersonIncident(incidentId, personId)')

This is my AR Code:

$criteria=new CDbCriteria;

$criteria->condition='id = "INM02932087"';

$testList=Incident::model()->with('persons')->findAll($criteria);

The Log also looks fine(see below), the last line shows the (correct) select statement that, when executed from SQLite Manager, returns one dataset.

But:

$testList contains my incident-Data,

$testList->persons is empty!!??!! it should contain one dataset in this case.

$testList[0]->_related contains an array persons that is <Uninitialized>

Am I doing something wrong or is it AR?

Thank you,

Michael

[11:42:43.506][trace][system.db.CDbCommand] Querying SQL: PRAGMA table_info('Person')

[11:42:43.508][trace][system.db.CDbCommand] Querying SQL: PRAGMA foreign_key_list('Person')

[11:42:43.518][trace][system.db.CDbCommand] Querying SQL: PRAGMA table_info('Incident')

[11:42:43.519][trace][system.db.CDbCommand] Querying SQL: PRAGMA foreign_key_list('Incident')

[11:42:43.520][trace][system.db.ar.CActiveRecord] Person.findAll() eagerly

[11:42:43.521][trace][system.db.CDbCommand] Querying SQL: SELECT 'Person'."id" AS t0_c0, 'Person'."dn" AS t0_c1, 'Person'."firstname" AS t0_c2, 'Person'."lastname" AS t0_c3, 'Person'."street" AS t0_c4, 'Person'."zipcode" AS t0_c5, 'Person'."city" AS t0_c6, 'Person'."company" AS t0_c7, 'Person'."phone" AS t0_c8, 'Person'."mobile" AS t0_c9, 'Person'."email" AS t0_c10 FROM 'Person'

[11:42:43.522][trace][system.db.CDbCommand] Querying SQL: PRAGMA table_info('PersonIncident')

[11:42:43.522][trace][system.db.CDbCommand] Querying SQL: PRAGMA foreign_key_list('PersonIncident')

[11:42:43.523][trace][system.db.CDbCommand] Querying SQL: SELECT 'Person'."id" AS t0_c0, t1."id" AS t1_c0, t1."location" AS t1_c1, t1."home" AS t1_c2, t1."assignment" AS t1_c3, t1."priority" AS t1_c4, t1."downtime_start" AS t1_c5, t1."downtime_end" AS t1_c6, t1."status" AS t1_c7, t1."alert" AS t1_c8, t1."opened_on" AS t1_c9, t1."modified_on" AS t1_c10, t1."work_start" AS t1_c11, t1."work_end" AS t1_c12, t1."duration" AS t1_c13, t1."downtime" AS t1_c14, t1."category" AS t1_c15, t1."hardware" AS t1_c16, t1."software" AS t1_c17, t1."description" AS t1_c18, t1."action" AS t1_c19, t1."resolution" AS t1_c20, t1."customer_info" AS t1_c21 FROM 'Person' LEFT OUTER JOIN 'PersonIncident' incidents_t1 ON ('Person'."id"=incidents_t1."personId") LEFT OUTER JOIN 'Incident' t1 ON (t1."id"=incidents_t1."incidentId") WHERE ('Person'."id"=1) AND (incidentId="INM02932088")

The log messages do not seem to be corresponding to the PHP statement you are executing. In particular, the first SQL query should be selecting from table Incident, not Person.

Ooops, please excuse my fault, I was doing cut&waste from the wrong window

[13:26:55.564][trace][system.db.CDbCommand] Querying SQL: PRAGMA table_info('Incident')

[13:26:55.579][trace][system.db.CDbCommand] Querying SQL: PRAGMA foreign_key_list('Incident')

[13:26:55.600][trace][system.db.CDbCommand] Querying SQL: PRAGMA table_info('Person')

[13:26:55.601][trace][system.db.CDbCommand] Querying SQL: PRAGMA foreign_key_list('Person')

[13:26:55.602][trace][system.db.ar.CActiveRecord] Incident.findAll() eagerly

[13:26:55.602][trace][system.db.CDbCommand] Querying SQL: SELECT 'Incident'."id" AS t0_c0, 'Incident'."location" AS t0_c1, 'Incident'."home" AS t0_c2, 'Incident'."assignment" AS t0_c3, 'Incident'."priority" AS t0_c4, 'Incident'."downtime_start" AS t0_c5, 'Incident'."downtime_end" AS t0_c6, 'Incident'."status" AS t0_c7, 'Incident'."alert" AS t0_c8, 'Incident'."opened_on" AS t0_c9, 'Incident'."modified_on" AS t0_c10, 'Incident'."work_start" AS t0_c11, 'Incident'."work_end" AS t0_c12, 'Incident'."duration" AS t0_c13, 'Incident'."downtime" AS t0_c14, 'Incident'."category" AS t0_c15, 'Incident'."hardware" AS t0_c16, 'Incident'."software" AS t0_c17, 'Incident'."description" AS t0_c18, 'Incident'."action" AS t0_c19, 'Incident'."resolution" AS t0_c20, 'Incident'."customer_info" AS t0_c21 FROM 'Incident' WHERE (id = "INM02932087")

[13:26:55.604][trace][system.db.CDbCommand] Querying SQL: PRAGMA table_info('PersonIncident')

[13:26:55.604][trace][system.db.CDbCommand] Querying SQL: PRAGMA foreign_key_list('PersonIncident')

[13:26:55.605][trace][system.db.CDbCommand] Querying SQL: SELECT 'Incident'."id" AS t0_c0, t1."id" AS t1_c0, t1."dn" AS t1_c1, t1."firstname" AS t1_c2, t1."lastname" AS t1_c3, t1."street" AS t1_c4, t1."zipcode" AS t1_c5, t1."city" AS t1_c6, t1."company" AS t1_c7, t1."phone" AS t1_c8, t1."mobile" AS t1_c9, t1."email" AS t1_c10 FROM 'Incident' LEFT OUTER JOIN 'PersonIncident' persons_t1 ON ('Incident'."id"=persons_t1."incidentId") LEFT OUTER JOIN 'Person' t1 ON (t1."id"=persons_t1."personId") WHERE ('Incident'."id"='INM02932087')

Did you try executing the 2nd SQL manually? What is the result?

The 2nd sql-statement returns one row of data

the data starts with

t0_c0,t1_c0,…

"INM02932087","1",…

and then all the person data I expect to see, also, the 1 is the id of this person, so everything seems to be correct but the data seems not to be copied into the persons array.

Could you please create a ticket for this? It would better if you could create a small example that would allow me to reproduce the issue (we do have similar unit test, but it runs without problem).

Thanks!

I have created a small demo app and opend a bug

Hope it helps,

Michael

Thanks.