Yii Framework Forum: Making relational AR easier - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Making relational AR easier Rate Topic: -----

#1 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,900
  • Joined: 04-October 08
  • Location:DC, USA

Posted 10 June 2009 - 06:57 AM

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!

1. 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.

2. 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".

0

#2 User is offline   PoL 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 506
  • Joined: 05-November 08
  • Location:Buenos Aires, Argentina

Posted 10 June 2009 - 07:38 AM

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...

2.- I thinks is good too...
0

#3 User is offline   ricardograna 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 376
  • Joined: 31-March 09
  • Location:Manaus/AM - Brazil

Posted 10 June 2009 - 07:42 AM

I think both are interesting and useful. It will break some codes, but this behavior will be better.
0

#4 User is offline   olafure 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 04-March 09
  • Location:Iceland

Posted 10 June 2009 - 11:03 AM

1. Yes! (it took me a while to figure out to start with).  I actually can't see any drawbacks, are there any ?

2. 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)
0

#5 User is offline   Junior - df9 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 416
  • Joined: 24-May 09
  • Location:Brazil

Posted 10 June 2009 - 06:28 PM


in my opinion, good! go ahead!

:)
0

#6 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 11 June 2009 - 10:01 AM

1. 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.
0

#7 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,900
  • Joined: 04-October 08
  • Location:DC, USA

Posted 13 June 2009 - 03:06 PM

Thank you all for your suggestions.

I just checked in the code for these changes. Yes, the 'alias' option is still available so that we can explicitly specify the table alias.

Please let me know if you experience any problem with these changes. Thanks!
0

#8 User is offline   Ismael 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 163
  • Joined: 02-June 09
  • Location:Brazil

Posted 19 June 2009 - 04:17 PM

I'm not a Yii veteran.

But all these changes will conflit with olders already made?
It's easy to upgrade?
0

#9 User is offline   creocoder 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 199
  • Joined: 09-March 09
  • Location:*.php

Posted 22 June 2009 - 11:35 AM

Quote

Because they may break some existing code

If 1.1 will break some existing code, let it be. Best if yii be without "historical reasons".
0

#10 User is offline   Ismael 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 163
  • Joined: 02-June 09
  • Location:Brazil

Posted 22 June 2009 - 12:44 PM

I had some problems when migrate Rails 1.3 to 2.0.

Fatal error in the entire website!

There should be at least a step-by-step migrating to new code.
But I agree with:

Quote

If 1.1 will break some existing code, let it be. Best if yii be without "historical reasons".

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users