If Coupon belongsTo Merchant and Merchant hasMany Address, then you'd
need recursive=2 to get the Address from a find on Coupon.

If you want to handle it all in a single find, I'd strongly suggest
using the Containable behavior; recursive=2 finds tend to be quite
slow and fetch a lot of redundant, unnecessary data without it.

hth
grigri

On Feb 11, 7:37 pm, Jesse <jesseainsk...@gmail.com> wrote:
> I know that HABTM problems are pretty frequnt. I've been doing lots of
> research and almost got this figured out. A little boost would really
> be appreciated.
>
> The Downlow...
>
> Merchants
> Merchants hasMany Addresses
> Merchants hasMany Coupons
> Coupons HABTM tags
> tags HABTM coupons
>
> I've got a search for the tags area that then returns the Coupon
> information. Everything works fine except I need to pull some more
> information. My problem is I am unbinding/binding information on the
> fly to do the search and I think this is causing my recursion problem.
> Here's the code.
>
> $cat_count = count($conditions['OnsaleCouponsCategory.id']);
>
>                 $this->OnsaleCoupon->unbindModel(array
> ('hasAndBelongsToMany' => array('OnsaleCouponCategory')));
>                 $this->OnsaleCoupon->bindModel(
>                     array(
>                         'hasOne' => array(
>                             'OnsaleCouponsOnsaleCouponsCategory' =>
> array(
>                                 'foreignKey' => false,
>                                 'type' => 'INNER',
>                                 'conditions' => array
> ('OnsaleCouponsOnsaleCouponsCategory.onsale_coupon_id =
> OnsaleCoupon.id')
>                             ),
>                             'OnsaleCouponsCategory' => array(
>                                 'foreignKey' => false,
>                                 'type' => 'INNER',
>                                 'conditions' => array(
>                                     'OnsaleCouponsCategory.id =
> OnsaleCouponsOnsaleCouponsCategory.onsale_coupons_category_id',
>                                     //'OnsaleCouponsCategory.id' =>
> array(14)
>                                     'OnsaleCouponsCategory.id' =>
> $conditions['OnsaleCouponsCategory.id']
>                                 )
>                             )
>                         )
>                     )
>
>                 );
>
>                 $found_coupons = 
> $this->OnsaleMerchant->OnsaleCoupon->find('all', array(
>
>                         'recursive' => 1,
>                     'group' => array(
>                             'OnsaleCoupon.id',
>                             //'OnsaleCoupon.title HAVING COUNT(*) = 1'
>                             'OnsaleCoupon.title HAVING COUNT(*) = ' .
> $cat_count
>                     )
>                 ));
>
> Here a print_r for $found_coupons:
> Array
> (
>     [0] => Array
>         (
>             [OnsaleCoupon] => Array
>                 (
>                     [id] => 38
>                     [onsale_merchant_id] => 16
>                     [title] => Free Soft Drink!
>                     [content] => Get a free soft drink with the
> purchase of any meal!
>                     [datestart] => 2009-02-05 08:14:00
>                     [dateend] => 2009-02-05 08:14:00
>                     [retail_price] =>
>                     [sale_price] =>
>                 )
>
>             [OnsaleMerchant] => Array
>                 (
>                     [id] => 16
>                     [name] => Happy Joes Pizza
>                     [website] =>http://www.happyjoes.com
>                     [about_us] => About us!
>                     [hours] => Hours!
>                     [logo] => image/jpeg
>                     [onsale_merchants_category_id] => 2
>                 )
>
>             [OnsaleCouponsOnsaleCouponsCategory] => Array
>                 (
>                     [id] => 115
>                     [onsale_coupon_id] => 38
>                     [onsale_coupons_category_id] => 14
>                 )
>
>             [OnsaleCouponsCategory] => Array
>                 (
>                     [id] => 14
>                     [title] => American
>                     [onsale_coupons_categories_division_id] => 3
>                     [0] => Array
>                         (
>                             [id] => 3
>                             [title] => Golfing
>                             [onsale_coupons_categories_division_id] =>
> 4
>                             [OnsaleCouponsOnsaleCouponsCategory] =>
> Array
>                                 (
>                                     [id] => 117
>                                     [onsale_coupon_id] => 38
>                                     [onsale_coupons_category_id] => 3
>                                 )
>
>                         )
>
>                     [1] => Array
>                         (
>                             [id] => 11
>                             [title] => Chinese
>                             [onsale_coupons_categories_division_id] =>
> 3
>                             [OnsaleCouponsOnsaleCouponsCategory] =>
> Array
>                                 (
>                                     [id] => 116
>                                     [onsale_coupon_id] => 38
>                                     [onsale_coupons_category_id] => 11
>                                 )
>
>                         )
>
>                     [2] => Array
>                         (
>                             [id] => 14
>                             [title] => American
>                             [onsale_coupons_categories_division_id] =>
> 3
>                             [OnsaleCouponsOnsaleCouponsCategory] =>
> Array
>                                 (
>                                     [id] => 115
>                                     [onsale_coupon_id] => 38
>                                     [onsale_coupons_category_id] => 14
>                                 )
>
>                         )
>
>                     [3] => Array
>                         (
>                             [id] => 6
>                             [title] => Let's Eat Out
>                             [onsale_coupons_categories_division_id] =>
> 1
>                             [OnsaleCouponsOnsaleCouponsCategory] =>
> Array
>                                 (
>                                     [id] => 118
>                                     [onsale_coupon_id] => 38
>                                     [onsale_coupons_category_id] => 6
>                                 )
>
>                         )
>
>                 )
>
>         )
>
> The problem is that I need to pull all the merchant information, along
> with the Merchant's Addresses. As of now I get the Merchant info, but
> it doesn't drill down to their addresses. I think I have to make a
> seperate query and pull these and associate them on the fly. What do
> you guys think? Any suggestions?
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to