Status update: ActiveRecord

What I really like: It seems to be a lot easier now to create a data provider from a relation. This wasn’t possible in Yii 1.x as you had no access to the underlying db criteria object (it just returned a simple array). That was a huge pain for me in 1.x

I like that new feature, and improvement for STAT more adaptive conversion from query to AR

Hi is new active record support relation save like the behavior with-relation already build for 1.1?, i looked the code of activerecord but did not see anything for this purpose, mr qiang said before it implemented, but could not find the guid for this subject

Look at the methods "link" and "unlink" on "ActiveRecord" class

https://github.com/yiisoft/yii2/blob/master/framework/db/ActiveRecord.php#L1150

https://github.com/yiisoft/yii2/blob/master/framework/db/ActiveRecord.php#L1225

I think i’ve read it somewhere but i’m not sure anymore. The code seems to confirm it though: There’s no JOIN query at all anymore for any relational query, is that right? Related records are always fetched through separate queries?

It would seem so. Is there no risk of performance issues in running the relational query with a large number of base table ID’s? Also, how are composite keys handled?

Mike

Yes. Usually first query is getting a list of IDs, second one is getting records themselves. That’s actually a bit faster and caching-friendly.

Ok, thanks. Even though i don’t agree that 2 queries are faster per se, i see the point in this design decision. Querying related records in Yii1 could become a real pain in complex scenarios. The implementation is probably much more lightweight and understandable. Will have a closer look ;)

Sorry, I’m a current Yii 1.1 developer and was trying to follow the discussions in this post, but I kinda got lost.

One of the things I noticed strange in the new AR is the idea of having to use explicit joins with raw SQL when you need to filter a table through another. Would this be alleviated by the generic aliases discussed here (such as @self and @foreign)?

What’s the problem with using something like ->with(‘relation_name’) or ->together()? As a system’s developer (and not Yii Core developer) I see those two approaches MUCH easier to be used, as they give more readability and flow to the AR querying code.