Status update: ActiveRecord

Is there a way we can configure stored procedures operations for the ones we want?
Right now, I'm not using them because of lack of support from Yii but have used them extensively in the past.
I have used iBatis (now MyBatis) in Java to create the data mappings between everthing.
I know it's more work but also, its more powerful.MyBatis

Also, some extensions like with-related-behavior delete all MANY_MANY relations in the in-between-table, and then remake them. I know there won't be MANY_MANY relations in v2, but I just want to point out that such a behavior isn't optimal.

Also, some extensions like with-related-behavior delete all MANY_MANY relations in the in-between-table, and then remake them. I know there won't be MANY_MANY relations in v2, but I just want to point out that such a behavior isn't optimal.

I am adressing these problems in my Extension ActiveRecordRelationBehavior, which might be of interest for you and others who need the comfort of saving related records directly with save(). This one keeps entries in MANY_MANY table btw.

* The relation declaration syntax is changed. We now only differentiate two kinds of relations: has one and has many. Foreign key constraints are specified using 'link' option. And the 'via' option is equivalent to the 'through' option in 1.x.

If I may ask, what is the advantage of dropping the MANY_MANY type of relation?

Jeroendh
1. It was introduced when there was no through option for relations that's much more flexible. In Yii2 it's called via, has significantly better syntax and is generally simpler to define.
2. If you're going not only to display data but to add it, you need model for the "middle" table anyway.
3. If you're going to have data in the "middle" table, you can't use MANY_MANY to get this data.

2. Why do we need to setup a link in the items relation? Isnt that set in the OrderItem class?

That way it could be:

// via another relation
'items:Item[]' => array(
'via' => 'orderItems.item', //links are set in orderItems relation and in the item relation of the OrderItem class
),

3. The @'s in the relations of the Order model confuse me. @ is the self table, right? ie, tbl_order. Should it be 'order' => '?.id' and 'on' => '?.category_id = 1' then?

4. To make things even more readable, what about adding the 'via' prequel as well? All links seem to be "That foreign attribute refers to this attribute of myself.", but that makes the link in the via-table relation look odd/unlogical.

1. orderItems is the name of relation, OrderItem is the model we're binding to, [] stays for "many".
2. To execute less code and in order for the code to be explicit. For example, you can have two different relations between two model using two different key pairs. In this case it's not possible to automatically determine which pair to use.
3. Most probably you're right. Both @ and ? are valid in an example (depending or what ordering we want to have and which fields are available) but using ? makes more sense.
4. I didn't quite get it. What should via. translate to in this case?

My main alternative suggestions are simply @self and @foreign (or maybe @other if that's something people like better). It doesn't take appreciably more effort to write and it is much clearer. I say this on the same topic as that one should use descriptive variable and function names instead of $r, $l and rvp() when coding, it's just common sense. It would also leave room for future @whatever when/if needed. See my earlier post for a more elaborate summary

I think Seal has a point too. It's not just about readability; Newcomers have enough to think about as it is, they shouldn't need to be troubled with memorizing weird symbols that have no intuitive meaning. Better have them learn @self and @other or something, it will make sense to them right from the start.

My main alternative suggestions are simply @self and @foreign (or maybe @other if that's something people like better). It doesn't take appreciably more effort to write and it is much clearer. I say this on the same topic as that one should use descriptive variable and function names instead of $r, $l and rvp() when coding, it's just common sense. It would also leave room for future @whatever when/if needed. See my earlier post for a more elaborate summary

I think Seal has a point too. It's not just about readability; Newcomers have enough to think about as it is, they shouldn't need to be troubled with memorizing weird symbols that have no intuitive meaning. Better have them learn @self and @other or something, it will make sense to them right from the start.

I couldn't agree more, @self and @other have my vote. Sure I can get used to the @ and ?, but we are planning to migrate our products to Yii and many of my collegues have to learn Yii. It's much more readable for a non-Yii programmer.

I may look like an idiot now, but I haven't seen a real example use of "?.". The ?/@foreign/@related/whatever, is it only usable/applicable inside relation definitions (where there is the local and only one foreign table)?

In Qiang's first post in this thread, he said "?." can be used "in queries and scopes to represent the table alias prefix to columns" and that it represents "the foreign table". This makes me wonder how (if at all) it applies in a query/scope where we have more than one foreign/related table. Take the following example:

// Yii 1.1 syntax.
// Find all posts for a public blogs and where the author's account is still active (whatever that means in this example).
Post::model()->with('blog', 'author')->findAll('blog.is_public=true and author.is_active=true');

// Yii 2.0 syntax (attempt).
// Find all posts for a public blogs and where the author's account is still active (whatever that means in this example).
Post::find()->with('blog', 'author')->where('blog.is_public=true and author.is_active=true')->all();

So in the above example, is "?." applicable, and if so what foreign/related table would it reference?