Yii Framework Forum: Status update: ActiveRecord - Yii Framework Forum

Jump to content

  • (7 Pages)
  • +
  • « First
  • 2
  • 3
  • 4
  • 5
  • 6
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

Status update: ActiveRecord

#61 User is offline   Luis Lobo Borobia 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 25-March 10
  • Location:Buenos Aires

Posted 27 May 2012 - 05:57 PM

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
Posted Image
The Social Network for Artists
0

#62 User is offline   yJeroen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 94
  • Joined: 06-September 11
  • Location:The Netherlands

Posted 02 June 2012 - 05:41 PM

To support rawtaz on the requirement for relational savings:

UI elements like the following should be able to use this. Those are very common elements to use in your app, which shouldnt require the current complexities of 1.1 to save.

CHtml::activeCheckBoxList()
CHtml::activeDropDownList()
CHtml::activeListBox()
CHtml::activeRadioButtonList()

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

#63 User is offline   CeBe 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 532
  • Joined: 16-July 10
  • Location:Berlin. Germany

Posted 02 June 2012 - 07:09 PM

View PostJeroendh, on 02 June 2012 - 05:41 PM, said:

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

#64 User is offline   yJeroen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 94
  • Joined: 06-September 11
  • Location:The Netherlands

Posted 07 June 2012 - 08:52 AM

View Postqiang, on 26 March 2012 - 09:23 AM, said:

* 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?
0

#65 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,743
  • Joined: 17-January 09
  • Location:Russia

Posted 07 June 2012 - 09:00 AM

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.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#66 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 07 June 2012 - 01:01 PM

4. Makes it easy to have a model for your "middle" table.
0

#67 User is offline   yJeroen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 94
  • Joined: 06-September 11
  • Location:The Netherlands

Posted 07 June 2012 - 02:39 PM

samdark, thank you for your insight.

What I do in Yii1 is just make two relationships. One hasmany to the middle table, and a manymany. I suppose we simplify things by only having two types of relationships.


If I can make another few questions:

1. Shouldnt Order have many orderItems in the example, instead of have one?
'orderItems:OrderItem[]' => array(    //added []
        'link' => array('order_id' => 'id'),
),


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.

class Order extends ActiveRecord
{
        public static function tableName()
        {
                return 'tbl_order';
        }

        public static function relations()
        {
                return array(
                        'customer:Customer' => array(
                                'link' => array('id' => 'customer_id'),
                        ),
                        'orderItems:OrderItem[]' => array(
                                'link' => array('order_id' => 'id'),
                        ),
                        // via another relation
                        'items:Item[]' => array(
                                'via' => 'orderItems.item',
                                'order' => '?.id',
                        ),
                        // via a join table
                        'books:Item[]' => array(
                                'joinType' => 'INNER JOIN',
                                'via' => array(
                                        'table' => 'tbl_order_item',
                                        'link' => array(
                                                'order_id' => 'id',
                                        ),
                                ),
                                'link' => array(
                                        'id' => 'via.item_id',  //added via., because item_id isnt an attribute of Order
                                ),
                                'on' => '?.category_id = 1',
                        ),
                );
        }
}



Maybe I need more coffee and Im making a fool of myself. Sorry in that case. :)
0

#68 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,743
  • Joined: 17-January 09
  • Location:Russia

Posted 07 June 2012 - 03:14 PM

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?
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#69 User is offline   rAWTAZ 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 102
  • Joined: 08-January 10

Posted 07 June 2012 - 03:22 PM

Still no more constructive opinions on the @ and ? symbols? I can't believe noone other than me and fsb find them to be less than ideal.
0

#70 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 07 June 2012 - 03:27 PM

I don't have a problem with '@:' and '?:' ;)
"Less noise - more signal"
0

#71 User is offline   Seal 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 126
  • Joined: 02-February 10

Posted 08 June 2012 - 03:03 AM

Sure one can get used to @ and ? but even now I am accepting these symbols (it requires getting used to it) but rAWTAZ has a point in that it is indeed not intuitive.

What I do like about these symbols are that they are short and quick to write especially in situations where you have many queries to make.

What are the short alternative?

Although a very trivial matter I can actually perceive a painful number of unnecessary forum questions regard this subject.
Sylvester La-Tunje

Posted Image
0

#72 User is offline   rAWTAZ 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 102
  • Joined: 08-January 10

Posted 08 June 2012 - 03:27 AM

View PostSeal, on 08 June 2012 - 03:03 AM, said:

What are the short alternative?

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

#73 User is offline   Hyprion 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 07-October 09
  • Location:Netherlands

Posted 08 June 2012 - 04:53 AM

View PostrAWTAZ, on 08 June 2012 - 03:27 AM, said:

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

#74 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,743
  • Joined: 17-January 09
  • Location:Russia

Posted 08 June 2012 - 05:02 AM

rAWTAZ
You have a good point actually. I don't like @other but @self is a good candidate to replace @. @foreign is probably OK for developers familiar with RDBMs.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#75 User is offline   Seal 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 126
  • Joined: 02-February 10

Posted 08 June 2012 - 05:31 AM

As long as it it short (less typing), its all good for me.

@self has my vote too
Sylvester La-Tunje

Posted Image
0

#76 User is offline   rAWTAZ 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 102
  • Joined: 08-January 10

Posted 08 June 2012 - 05:34 AM

Seal, what do you vote for the other part, @foreign or @other or something else?

Love your looks by the way :mellow:
0

#77 User is offline   Seal 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 126
  • Joined: 02-February 10

Posted 08 June 2012 - 05:52 AM

well
'@foreign'
because it makes the most sensePosted Image

In attempt to think out of the box, I will throw-in @link,





Sylvester La-Tunje

Posted Image
0

#78 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,358
  • Joined: 12-October 09
  • Location:Croatia

Posted 08 June 2012 - 05:54 AM

How about @related ?
Find more about me.... btw. Do you know your WAN IP?
0

#79 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 08 June 2012 - 06:00 AM

@self/@this and @rel (from mdomba's @related).
0

#80 User is offline   rAWTAZ 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 102
  • Joined: 08-January 10

Posted 08 June 2012 - 06:42 AM

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?
0

Share this topic:


  • (7 Pages)
  • +
  • « First
  • 2
  • 3
  • 4
  • 5
  • 6
  • Last »
  • 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