Thanks, That explains it quite well for me. It has been one of those thing at the back of my mind since I keep seeing both used, seemingly, interchangeably in examples all over the web. I guess I do a bit of search and replace for the places I have used this->name. :)
Martin On Sep 11, 2:45 pm, grigri <[EMAIL PROTECTED]> wrote: > Most of the time you'll want $this->alias > > The difference appears in associations: > > class Post extends AppModel { > var $belongsTo = array( > 'Author' => array('className' => 'User') > ); > > } > > When this association is active, the `User` model class will have > $this->name=='User' but $this->alias=='Author'. > > For callbacks, you should use $this->alias in most cases (although > *most* of the time they will be the same anyway). > > For your example btw, use $this->id to get the primary key value. For > others though: > > (example) > $the_title = $this->data[$this->alias][$this->displayField] > > hth > grigri > > On Sep 11, 1:09 pm, "[EMAIL PROTECTED]" > > <[EMAIL PROTECTED]> wrote: > > Hi, > > I have seen tutorials and example-code using either $this->name or > > $this->alias. Which one of preferable? > > > Example: > > $the_id = $this->data[$this->name][$this->primaryKey]; > > or > > $the_id = $this->data[$this->alias][$this->primaryKey]; > > > I am not clear about which one I should use in my AppModel or any > > beforeSave or other hooks. The only difference I have noticed myself > > is that in 1.2 beta I had problems with one of them in tests... but > > both look Ok now. > > > What's the difference? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---