Tuesday, August 24, 2010

Re: Relationships

On Aug 24, 2010, at 6:03 PM, cricket wrote:

> On Tue, Aug 24, 2010 at 2:31 PM, Philip Thompson <philthathril@gmail.com> wrote:
>> Hi all.
>>
>> Sorry for all these newb questions... trying to learn this stuff. Here's the relationships and tables I have:
>>
>> Relationships:
>> Hardware HABTM Configuration
>> Configuration belongsTo ConfigurationType
>>
>> Tables:
>> configurations
>> - configuration_type_id
>> configurations_hardwares
>> - configuration_id
>> - hardware_id
>> configuration_types
>> hardwares
>>
>> When pulling the information for a specific Hardware record, I'm successfully getting the Configurations associated with it, but I'm not getting the information from the configuration_types table. How do I get info from this other table?
>>
>> <?php
>> $options['conditions'] = array('Hardware.id'=>$id);
>> $this->Hardware->find('first', $options);
>> ?>
>>
>> produces...
>>
>> Array
>> (
>> [Hardware] => Array
>> (
>> [id] => 3
>> [hardware_type_id] => 2
>> [name] => w-irv-win7dev
>> [description] => Philip Thompson's Windows 7 machine
>> [location_id] => 1
>> )
>>
>> [Configuration] => Array
>> (
>> [0] => Array
>> (
>> [id] => 1
>> [configuration_type_id] => 1
>> [configuration] => Windows 7 Professional
>> [description] =>
>> [ConfigurationsHardware] => Array
>> (
>> [id] => 1
>> [configuration_id] => 1
>> [hardware_id] => 3
>> )
>> )
>>
>> [1] => Array
>> (
>> [id] => 3
>> [configuration_type_id] => 5
>> [configuration] => Yes
>> [description] =>
>> [ConfigurationsHardware] => Array
>> (
>> [id] => 2
>> [configuration_id] => 3
>> [hardware_id] => 3
>> )
>> )
>> )
>> )
>>
>> I get the configuration_type_id result, but I want other fields from configuration_type. Any help would be greatly appreciated on how to accomplish this!
>>
>
> You need to increase the "recursive" value:
>
> $options['recursive'] = 2;
>
> I recommend you take a look at ContainableBehavior, though. It gives
> one much more control (recursive == 2 can fetch too much data).

Excellent! Thanks for your help. It worked!

~Philip

http://lonestarlightandsound.com/

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: