Thursday, October 28, 2010

After upgrade from 1.2.x to 1.3.5: related models aren't loaded automatically anymore?

Hey guys

Yes, it's me again... Cleaning up some dirty codes from my antecessor.

I have a User model that can export some INI data with a getIni()
method. The User model is related to many different models that server
some data for the INI data:

function getIni() {
$data = '';
$data .= 'street='.$this->Location->field('street');
$data .= 'zip='.$this->Location->field('zip');
// etc.
return $data;
}

Now I noticed that every user had the same location street and zip,
although they are not all related to the same location!

So I found out that $this->Location didn't point to the related
location, but to always the same location!

I know that it's no good style to always use field(...), because every
call causes a new DB query, so I will rewrite this stuff to use $this-
>data['User']['Location']['street'] etc. instead (which DOES have the
right data in it, thank god!). So my question is just: why did this
use to work in the past and doesn't anymore in the present? Does it
have to do with $recursive or something?

Thanks,
Josh

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: