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

Jump to content

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

Status update: ActiveRecord

#101 User is offline   jacmoe 

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

Posted 15 June 2012 - 05:37 AM

It is not trivial at all.

@self and @relative is going to be used a lot, so it should as clear and self-descriptive as possible, even if it means that we nitpick.

It can maybe be seen as trivial when you look at it in isolation; just remember that a framework is essentially a collection of trivial things.
Which makes them non-trivial. ;)
"Less noise - more signal"
0

#102 User is offline   Mike 

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

Posted 15 June 2012 - 05:39 AM

Oh no ... Posted Image
0

#103 User is offline   Coksnuss 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 14-May 09

Posted 16 June 2012 - 11:38 AM

In the example of page one we have the table

tbl_order_item
> order_id (FK1, PK)
> item_id (FK2, PK)
> quantity
> subtotal
> id

Has the new framework an approach implemented to access the "meta-informations" in the join table (namely: quantity, subtotal and id)?
1

#104 User is offline   samdark 

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

Posted 16 June 2012 - 04:01 PM

Coksnuss
Yes.
Yii 1.1 Application Development Cookbook

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

#105 User is offline   fsb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 123
  • Joined: 09-January 11

Posted 17 June 2012 - 03:11 PM

View Postseb, on 13 June 2012 - 12:02 AM, said:

Regarding the use of "?" - as I remember there was such feature in Yii 1.0 where we had aliasToken in CActiveRelation class, so we could use something like "??.name" to refer related table column.
And (I may be wrong) it only worked when you have one relation - in other cases you had to set aliasToken properties for relations manually. So I guess here we can have similar situation - '?' will work only when one related table is involved.



is this correct?

@related will work in queries and scopes ONLY when the model has exactly one relation?
Join the happiest place on Freenode: #yii
We've got a MrFisk the bot, hilarious banter and all kinds of other groovy stuff going on.
Comparison of Internet Relay Chat clients
Web IRC client
0

#106 User is offline   CeBe 

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

Posted 17 June 2012 - 03:21 PM

View Postfsb, on 17 June 2012 - 03:11 PM, said:

@related will work in queries and scopes ONLY when the model has exactly one relation?

Guess it is only valid in conditions we define for a specific relation to enable yii to choose a different alias name if they are ambigous. This was not possible in 1.1
0

#107 User is offline   fsb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 123
  • Joined: 09-January 11

Posted 18 June 2012 - 07:50 AM

View PostCeBe, on 17 June 2012 - 03:21 PM, said:

Guess it is only valid in conditions we define for a specific relation to enable yii to choose a different alias name if they are ambigous.


I guess so too. But what are these conditions?



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

* The token "@." and "?." can be used in queries and scopes to represent the table alias prefix to columns. The former represents the self table, the latter the foreign table.


Given the code he presented in that original post, can anyone devise examples of the use of ?. (or @related.) in queries and scopes?
Join the happiest place on Freenode: #yii
We've got a MrFisk the bot, hilarious banter and all kinds of other groovy stuff going on.
Comparison of Internet Relay Chat clients
Web IRC client
0

#108 User is offline   yJeroen 

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

Posted 09 July 2012 - 03:46 PM

Maybe I missed this, but will the new ActiveRecord support saving related models? And if so, what will the syntax be?

(samdark said this is a good thing about Eloquent in a different thread, but I thought this would be the better place to ask. :) )
0

#109 User is offline   samdark 

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

Posted 09 July 2012 - 06:33 PM

yJeroen
Most probably yes. There will be dirty attributes support so it will be relatively straightforward to save related records. Currently there's no support for it and I'm not sure if it will be in github alpha release.
Yii 1.1 Application Development Cookbook

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

#110 User is offline   Müller 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 23-June 12
  • Location:Netherlands

Posted 14 August 2012 - 07:49 AM

I vote for
@own and @rel

Both just 4 chars. I think shortcuts for table name/alias was one of reasons why this was introduced, so keep it short. It's also readable. e.g.:
'on' => '@own.type = "product" AND @rel.amount > 0'



View Postjacmoe, on 15 June 2012 - 05:37 AM, said:

It is not trivial at all.

@self and @relative is going to be used a lot, so it should as clear and self-descriptive as possible, even if it means that we nitpick.

It can maybe be seen as trivial when you look at it in isolation; just remember that a framework is essentially a collection of trivial things.
Which makes them non-trivial. ;)

0

#111 User is offline   seb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 29-June 09

Posted 14 August 2012 - 08:22 AM

On another topic, regarding the eager loading:

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

// eager relational query
$customers = Customer::find()->with('orders')->all(); 



Now there are some not obvious (at least from the beginning) rules to automatically detect whether relation should be eagerly or lazy loaded:
- one-to-one relation will be eagerly loaded
- one-to-many / many-many relation will be lazy loaded if 'limit' is set (query paginated) or eagerly loaded otherwise
- if we set 'together' option then one-to-many / many-many relation will be eagerly loaded (regardless of 'limit')

Will this be changed somehow in a new active record version?
0

#112 User is offline   phazei 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 20-July 09

Posted 16 August 2012 - 03:55 PM

In 1.1 I modified the generator so when creating a many-many instead of an if/else check depending on if it was a relation table, I just had it create both and modified the template to add a "//pivot table" comment next to the tables that were relational.

That way I get both many_many tables along with pivot table relations in case of meta data.
It would be nice to have access to both in 2.0.

edit:
Also, occasionally there's a many_many relation where the pivot table would have
> id (PK)
> order_id (FK1, PK)
> item_id (FK2, PK)
And the relation is just through 'order' and 'item', but there's a id as well. Would be nice if while checking if there is a many_many relation it could skip id if there were 3 pk's. But that's probably a fringe case.




View PostCoksnuss, on 16 June 2012 - 11:38 AM, said:

In the example of page one we have the table

tbl_order_item
> order_id (FK1, PK)
> item_id (FK2, PK)
> quantity
> subtotal
> id

Has the new framework an approach implemented to access the "meta-informations" in the join table (namely: quantity, subtotal and id)?

0

#113 User is offline   Sampa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 18-December 11
  • Location:Stockholm,Sweden

Posted 17 August 2012 - 02:41 AM

I just learned scopes:( now I will have to re learn it haha. doh .

Looks like overall good improvements. With fewer find() methods it will be alot easier to learn yii imho, I remember it beeing very confusing "which one should I use??? waahh"

A question,
foreach(Customer::find() as  $customer


Does this mean $customers = Customer::find() works to? or is $Customers::find()->all() a must?
0

#114 User is offline   Sampa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 18-December 11
  • Location:Stockholm,Sweden

Posted 17 August 2012 - 02:49 AM

$model->save(array('related'=>array('relationName'=>array($relatedModels)));

Would this be nice? would be easy atleast to build the array and then just write $model->save($array);
And it would support several relations and several records per relation.

Just an idea
0

#115 User is offline   Sampa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 18-December 11
  • Location:Stockholm,Sweden

Posted 17 August 2012 - 02:55 AM

View Postjacmoe, on 08 June 2012 - 10:33 AM, said:

I don't like 'self' as it is used as 'this' in some languages.

How about @me and @rel ?

It's short. :)


I dont use other languages XD so for me @self sounds the most clear, after all "@me" sounds more like it's referring to the developer...

and not to forget, we use self in yii 1.1.X today:p would make the transition smoother and it's still very clear what it's refer to.

I vote for @self

about @rel and @related it's, a big HMMM. I agree with rawtaz I generally doent like shortened versions but in this case it feels like it is very clear what it refers to for most people.

I vote for @related but save me the possibility to change my mind :P
0

#116 User is offline   Tarzan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 22-August 11

Posted 29 August 2012 - 07:02 AM

Hi, I've writen my idea about active record's design. Here it is: http://www.yiiframew...s-activerecord/

Could you guys take a look and then give out your opinion?
0

#117 User is offline   yJeroen 

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

Posted 05 May 2013 - 08:05 AM

If I look at the following two pages, is the relations() method scrapped? Or just not implemented yet?
https://github.com/y...ActiveRecord.md
https://github.com/y...ctiveRecord.php

This new scheme of things also raises some questions:
  • If I load a relation using $model->relationName. the magic __get is used to load the relation getRelationName method into _related. However.. What if I want to reload the data?
  • Isn't a single place to define relations more straight forward? And then use __get and __set to manipulate your related data.


Note that if relations() is scrapped for the idea of seperate methods for each relationship and scope.. I'm thinking of always using two different behaviors for each of my models. One for relations and one for scopes. This way, it's more categorized imho.
0

#118 User is offline   samdark 

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

Posted 05 May 2013 - 08:09 AM

Relations now are to be implemented differently: https://github.com/y...ActiveRecord.md
Yii 1.1 Application Development Cookbook

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

#119 User is offline   yJeroen 

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

Posted 05 May 2013 - 09:21 AM

If I may ask, what were the pro's and con's to implement it like this?

With this implementation, if I have a model with eg. 5 relations, I need to create a method for each of them. They're also not grouped and since they look the same as other getXxx methods for custom attributes, in a list of all the methods in an IDE it can get unorganized.
0

#120 User is offline   samdark 

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

Posted 05 May 2013 - 04:34 PM

It's more explicit, better IDE support, one can add relations on the fly and via behaviors.
Yii 1.1 Application Development Cookbook

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

Share this topic:


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