Tuesday, March 4, 2014

Re: Simple belongsTo Association not working

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello you,

at the first glance everything looks just perfect!

I guess you have a retailer with id 3 set in the table?

you are absolutely sure that the output is caused by the line posted by
you? Do you get different results if you search for just one
Retailerfollow? And the calls is called "Retailerfollows" or
"Retailerfollow"? But that should be no Problem either....

one more thing: is the relatiopn deifined in both models? belongsTo and
hasMany in the other?

Sorry to be of no more help.


Calamity Jane


Am 04.03.2014 17:20, schrieb WhyNotSmile:
> I'm completely baffled by an association that's not working... I'm sure
> I've done this hundreds of times with no problems, but I just cannot see
> what's going on here! I think I must be missing something really obvious.
>
> So, I have 2 tables. One is called "Retailers" and all records in there
> have a unique id. The second is called "Retailerfollows" and it has the
> field "retailer_id"
>
> What I want is to be able to retrieve a Retailerfollows record, and to get
> the corresponding Retailer along with it.
>
> I have defined the following association in Retailerfollow.php:
>
>
>> public $belongsTo = array(
>> 'Retailer' => array(
>> 'className' => 'Retailer',
>> 'foreignKey' => 'retailer_id'
>> )
>> );
>>
>
> In my controller, I have:
>
> $this->Retailerfollow->recursive = 2;
>> debug($this->Retailerfollow->find('all'));
>>
>
> I don't think I should even need Recursive set to 2, but I'm trying
> anything I can think of!
>
> When I debug this, I get:
>
> array(
>> (int) 0 => array(
>> 'Retailerfollow' => array(
>> 'id' => '1',
>> 'retailer_id' => '3'
>> )
>> ),
>> (int) 1 => array(
>> 'Retailerfollow' => array(
>> 'id' => '3',
>> 'retailer_id' => '3'
>> )
>> )
>> )
>>
>>
> It's not retrieving the corresponding Retailer records. I've tried various
> things, including Containable behaviour, but with no success. I've checked
> spellings everywhere, but found nothing wrong. I've deleted the cache
> files, and that didn't help.
>
> I know it's probably something really simple, but I just can't spot it!
> Can anyone help, or suggest what I should try next to debug?
>
> Thanks!
>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)

iEYEARECAAYFAlMWMSAACgkQbOdiIJzHNKHJ1gCfTg8oaKYFAa3rhu7SveyFoVQs
KeIAnRC65lV3WleBGndXaTf05R/XKDrc
=laKV
-----END PGP SIGNATURE-----

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: