This almost works, but I get an error when I add the 'recursive' => 2.

Here is the error.

Warning (512): SQL Error: 1054: Unknown column
'OnsaleCouponsOnsaleCouponsCategory.onsale_coupons_category_id' in
'where clause' [CORE/cake/libs/model/datasources/dbo_source.php, line
514]

Code | Context

$sql    =       "SELECT `OnsaleCouponsCategory`.`id`,
`OnsaleCouponsCategory`.`title`,
`OnsaleCouponsCategory`.`onsale_coupons_categories_division_id` FROM
`onsale_coupons_categories` AS `OnsaleCouponsCategory`   WHERE
`OnsaleCouponsCategory`.`id` =
`OnsaleCouponsOnsaleCouponsCategory`.`onsale_coupons_category_id` AND
`OnsaleCouponsCategory`.`id` IN (6, 11)   "
$error  =       "1054: Unknown column
'OnsaleCouponsOnsaleCouponsCategory.onsale_coupons_category_id' in
'where clause'"
$out    =       null

            $out = null;
            if ($error) {
                trigger_error("<span style = \"color:Red;text-
align:left\"><b>SQL Error:</b> {$this->error}</span>",
E_USER_WARNING);

DboSource::showQuery() - CORE/cake/libs/model/datasources/
dbo_source.php, line 514
DboSource::execute() - CORE/cake/libs/model/datasources/
dbo_source.php, line 201
DboSource::fetchAll() - CORE/cake/libs/model/datasources/
dbo_source.php, line 337
DboSource::queryAssociation() - CORE/cake/libs/model/datasources/
dbo_source.php, line 809
DboSource::read() - CORE/cake/libs/model/datasources/dbo_source.php,
line 662
Model::find() - CORE/cake/libs/model/model.php, line 1951
OnsaleCouponsController::search() - /Users/jesseainskeep/Sites/
qconline-admin/www/htdocs/controllers/onsale_coupons_controller.php,
line 173
Object::dispatchMethod() - CORE/cake/libs/object.php, line 115
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 245
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 211
[main] - APP/webroot/index.php, line 88

Query: SELECT `OnsaleCouponsCategory`.`id`,
`OnsaleCouponsCategory`.`title`,
`OnsaleCouponsCategory`.`onsale_coupons_categories_division_id` FROM
`onsale_coupons_categories` AS `OnsaleCouponsCategory` WHERE
`OnsaleCouponsCategory`.`id` =
`OnsaleCouponsOnsaleCouponsCategory`.`onsale_coupons_category_id` AND
`OnsaleCouponsCategory`.`id` IN (6, 11)

I think this is because I am unbinding the relationship, then trying
to use the relationship. Any suggestions? I've tried everything I can
think of.



On Feb 12, 7:10 am, grigri <[email protected]> wrote:
> 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 <[email protected]> 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 [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