On Apr 19, 5:46 pm, MikeBates <[email protected]> wrote:
> I'm trying to limit an association between 2 models using the conditions key.
> It works great in the 'parent' Model, but I can't work out how to get it
> working properly in the 'child' Model.
>
> Here's the relevant info from the models:
> Product( 'id', 'name' );
> ProductLoan( 'id', 'product_number', 'product_numbr_is_id' );
>
> The hasMany association works fine in the Product Model:
> var $hasMany = array(
> 'ProductLoan' => array(
> 'className' => 'ProductLoan',
> 'foreignKey' => 'product_number',
> 'dependent' => false,
> 'conditions' => array(
> 'ProductLoan.product_number_is_id' => 1
> )
> );
>
> But I can't work out how to do the same thing in the belongsTo association
> in ProductLoan Model:
> var $belongsTo = array(
> 'Product' => array(
> 'className' => 'Product',
> 'foreignKey' => 'product_number',
> 'conditions' => array(
> 'ProductLoan.product_number_is_id' => 1
> ),
> 'fields' => '',
> 'order' => ''
> )
> );
This will associate each Product with the full set of ProductLoan that
have product_number_is_id == 1. You need to refine that to associate
it to a specific record:
var $belongsTo = array(
'Product' => array(
'className' => 'Product',
'foreignKey' => 'product_number',
'conditions' => array(
'ProductLoan.product_number_is_id' =>
1,
'Product.id` =>
'ProductLoan.product_number'
),
'fields' => '',
'order' => ''
)
);
I think.
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 [email protected]
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