Sometimes, recordset returned by SQL is not equal to findAll() one

Hi, I’m creating a webapp to manage Assurance agencies. When managing people involved in an accident I have Driver, Owner, Assured, Passenger and so on. To manage this I’ve used successfully the single table inheritance method.

Table ‘Person’ (that contains ALL people) is joined to table ‘Type’ (where I save person_id and person_type_id). The problem is when a Person is -for example- a Driver and Assured at the same time (it’s a common case…) and I do something like this:


 $people = Person::model()->with('type')->findAll($criteria);

it doesn’t return same number of records returned by SQL.

Of course, if I do the SQL generated by AR it returns correct number of records.

And of course, if in person_id in ‘Type’ table there aren’t duplicated number of records are the same in SQL and in AR too.

Any idea on why? I think it depends on ‘key’ assigned in array returned by AR. I think the key is PK of object. The same objects, the same keys… so it explains different result.

Cheers

Danilo

Solved using findAllBySql method, passing same query generated by findAll method as first argumento to findAllBySql one.

Now, I don’t know hwo to put [SOLVED] on title :(

Ah! Of course you don’t need to use “with”. So code is this:


$people = Person::model()->findAllBySql("[...SQL statement here...]",array(':field'=>$value));

there is no need to put [SOLVED] in the title… as anybody can in the future continue to post on this thread…