I believe this may be the same issue I'm experiencing.  After a bit of
investigation, I've found out the issue is that specifying "contain"
would appear to affect things in subsequent queries.

For example, say I have Cart hasMany CartedProduct belongsTo Product
belongsTo Brand.  Product also belongsTo VatRate.  (In other words,
CartedProduct is a linking table between Cart and Product.  It has a
quantity column, hence I'm not using hABTM.)  I might have a piece of
code like this, in a method of the Cart model:

// This is fine.  It displays products along with their brand.
$products = $this->CartedProduct->Product->find('all', array(
  'contain' => array(
    'Brand'
  )
));

pr($products);

// This causes issues
$ignore = $this->find('first', array(
  'conditions' => array(
    'Cart.id' => $cartID
  ),
  'contain' => array(
    'CartedProduct.Product.VatRate' => array(
      'fields' => array(
        'percentage'
      )
    )
  )
));

// This is now broken.  The brand is no longer displayed.
$products = $this->CartedProduct->Product->find('all', array(
  'contain' => array(
    'Brand'
  )
));

pr($products);

There are a few interesting things to note here:

Product is now broken, even though the query that broke it was
performed on Cart.

If I contain 'CartedProduct.Product.VatRate' then it's fine, but as
soon as I get as far as specifying its field, in this case
"percentage", it breaks.  This is regardless of whether I specify
'CartedProduct.Product.VatRate.percentage' or use the proper array-
based method above.

By "breaking", I specifically mean that any subsequent queries
regarding products will only show data that meet the contain criteria
above as well as any new contain criteria.

I would expect this from unbindModel() if I was telling it to remember
the unbinding, but I wouldn't expect it from a contain argument passed
to find().

I've checked, and yes, Product does still belongTo both Brand and
VatRate after the query.  A pr() of $this->CartedProduct->Product and
of $this (the Cart) show that both are identical before and after the
troublesome query.

Before anyone asks, I'm using CakePHP version 8166.

I've implemented a temporary workaround: because I know I want Brand
in a subsequent query, I'm including it in the contain in the query
that breaks the subsequent ones.  However, that's not a viable long-
term solution as I'm concerned that I may have some other piece of
code somewhere that thinks it's pulling out important data that it now
isn't.

Is this a bug?  should I go ahead and report it?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to