I am thinking to introduce two more changes to AR to make relational query easier to use. Because they may break some existing code, I would like to hear your opinions. Thanks!
Use relation name as table alias by default. Currently, Yii will automatically generate an alias (e.g t1) if the ‘alias’ option is not specified in the relation declaration. I realized in most cases, if we want to filter according to related table columns, we would need to set their aliases, which is very inconvenient. Using automatic alias has the benefit that it eliminates the possibility of duplicated table aliases. But I think this benefit doesn’t offset its drawback.
Use "join together()" by default. Currently, by default Yii will break a relational query into several ones depending on the number of HAS_MANY and MANY_MANY relations. This is mainly to improve performance. A drawback is that it becomes impossible to specify filtering conditions on the related table columns. Therefore, we have to call together() after with() to ensure Yii don't break the query. I realized that such filtering usage is very common. So I think it would be better if we "join together" by default. If one wants to optimize the query, he can choose not to "join together".
1.- I think yhis is very good, another good point is that when we see the log the query is more readable… I think too that remain the posibility to specify other alias than the default…
Yes! (it took me a while to figure out to start with). I actually can't see any drawbacks, are there any ?
I think it might make it easier to use, so yes. Perhaps the documentation hasn't been very clear on "how to filter related table columns".
Also, if this new way will be the default, it would make sense to have a "optimize tip" in the documentation, saying that if you don't need to filtering in related tables then to use apart() (or whatever it will be called)
I support this change as long as we can set another alias manually. This is necessary to be able to have different relations to the same table. Can be useful in some cases.