I got this working by using Andy's workaround here:

http://groups.google.com/group/cake-php/browse_frm/thread/8cbf01f7a9acda57/9e84f7aacbf3cd85?#9e84f7aacbf3cd85

Essentially, I had to bind a dummy a hasOne relationship:

function listByDisciplineAndType()
{
        $discipline = 
$this->__getDisciplineBySlug($this->params['discipline_slug']);
        $fund_type = 
$this->__getFundTypeBySlug($this->params['fund_type_slug']);

        $this->Fund->recursive = 0;
        
$this->Fund->bindModel(array('hasOne'=>array('FundsDisciplines'=>array())));
        
        $fields = array('Fund.id', 'Fund.name', 'Fund.short_description');
        $criteria = array(
                'conditions' => array(
                        'Fund.fund_type_id' => $fund_type_id,
                        'FundsDisciplines.discipline_id' => $discipline_id
                )
        );
        
        $this->set('discipline', $discipline);
        $this->set('fund_type', $fund_type);
        //$this->set('funds', $this->paginate('Fund', $criteria));
        $this->set('funds', $this->Fund->find('all', $criteria, $fields));
}

Two things, though:
1)the $fields array is being ignored. I'd love to hear from anyone who
can tell me why as I'm getting far more data than I need or want,
because ...
2) pagination doesn't work at all. If I try the commented paginate()
call abaove, I get the all-too familiar error that FundsDisciplines is
not in the FROM clause. I guess I can understand why that's happening
(and, after 8+ hours on this one problem, I really should understand
it better) but this seems like a huge omision in pagination. Or I'm
still just missing something. I checked out this article:

http://cakebaker.42dh.com/2007/10/17/pagination-of-data-from-a-habtm-relationship/

but that's no help here because it still does nothing for the join on
disciplines.

Anyone?

On Sat, Mar 8, 2008 at 3:17 PM, b logica <[EMAIL PROTECTED]> wrote:
> Yes, I got my associationForeignKey and foreignKey entries reversed. I
>  fixed that but still the same.
>
>  I've also tried 'FundsDisciplines.discipline_id' => $discipline_id in
>  the conditions but that just makes Cake neglect to put that table in
>  the FROM clause, instead.
>
>  Ignore the "ask_" and "ASK" stuff: I wanted to simplify the names and
>  forgot to remove those.
>
>
>
>  On Sat, Mar 8, 2008 at 3:00 PM, b logica <[EMAIL PROTECTED]> wrote:
>  > Anyone? I've been hashing over this for hours now and the clue-fairy
>  >  hasn't made an appearance yet. Ican't believe this is impossible to do
>  >  with Cake so I must have something wrong somewhere.
>  >
>  >
>  >
>  >
>  >  class Fund extends AppModel
>  >  {
>  >         var $name = 'Fund';
>  >
>  >         var $useTable = 'funds';
>  >         var $belongsTo = array('FundType');
>  >
>  >         var $hasAndBelongsToMany = array(
>  >                 'Discipline' => array(
>  >                         'className' => 'Discipline',
>  >                         'joinTable' => 'funds_disciplines',
>  >                         'foreignKey' => 'discipline_id',
>  >                         'associationForeignKey' => 'fund_id'
>  >                 )
>  >         );
>  >
>  >  }
>  >
>  >  class AskFundType extends AppModel
>  >  {
>  >         var $name = 'AskFundType';
>  >
>  >         var $useTable = 'fund_types';
>  >         var $hasMany = 'Fund';
>  >
>  >  }
>  >
>  >  class Discipline extends AppModel
>  >  {
>  >         var $name = 'Discipline';
>  >
>  >         var $hasAndBelongsToMany = array(
>  >                 'AskFunder' => array(
>  >                         'className' => 'AskFunder',
>  >                         'joinTable' => 'ask_funders_disciplines',
>  >                         'foreignKey' => 'ask_funder_id',
>  >                         'associationForeignKey' => 'discipline_id'
>  >                 ),
>  >         );
>  >  }
>  >
>  >
>  >  class FundsController extends AppController
>  >  {
>  >         var $name = 'Funds';
>  >
>  >         var $paginate = array(
>  >                 'limit' => 10,
>  >                 'page' => 1,
>  >                 'order'=>array('Fund.name' => 'ASC'),
>  >                 'fields' => array(
>  >                         'Fund.id',
>  >                         'Fund.name',
>  >                         'Fund.short_description'
>  >                 )
>  >         );
>  >
>  >         function listByDisciplineAndType()
>  >         {
>  >
>  >                 ...
>  >
>  >                 $conditions = array(
>  >                         'Fund.fund_type_id' => $fund_type_id,
>  >                         'Discipline.id' => $discipline_id
>  >                 );
>  >
>  >                 $this->set('funds', $this->paginate('Fund', $conditions));
>  >         }
>  >         ...
>  >
>  >  The really strange thing is, if i remove "'Discipline.id' =>
>  >  $discipline_id" from the $conditions, I get:
>  >
>  >  Array
>  >  (
>  >     [0] => Array
>  >         (
>  >                 [Fund] => Array
>  >                 (
>  >                         [id] => 168
>  >                         [name] => THE_FUND_NAME
>  >                         [short_description] => THE_FUND_DESCRIPTION
>  >                 )
>  >
>  >                 [Discipline] => Array
>  >                 (
>  >                 )
>  >         )
>  >         ...
>  >  )
>  >
>  >  So, why is it that Cake refuses to select on disciplines but still
>  >  adds the Discipline array (albeit empty) here? What the heck is going
>  >  on?
>  >
>  >
>  >
>  >
>  >
>  >  On Sat, Mar 8, 2008 at 2:10 AM, [EMAIL PROTECTED]
>  >  <[EMAIL PROTECTED]> wrote:
>  >  >
>  >  >  (Cake1.2, using Bindable)
>  >  >
>  >  >  Just when I thought I had this figured out...
>  >  >
>  >  >  I have 3 models:
>  >  >
>  >  >  Fund => belongsTo (FundType), HABTM(Discipline)
>  >  >  FundType => hasMany(Fund)
>  >  >  Discipline => HABTM(Fund)
>  >  >
>  >  >  FundsController:
>  >  >
>  >  >  function listByDisciplineAndType()
>  >  >  {
>  >  >         $discipline_slug = $this->params['discipline_slug'];
>  >  >         $fund_type_slug = $this->params['fund_type_slug'];
>  >  >
>  >  >         $fields = array('Fund.name', [Fund.etc...]);
>  >  >         $criteria = array(
>  >  >                 'conditions' => array(
>  >  >                         'Discipline.slug' => $discipline_slug,
>  >  >                         'FundType.slug' => $fund_type_slug
>  >  >                 ),
>  >  >                 'restrict' => array(
>  >  >                         'Discipline(name, slug)',
>  >  >                         'FundType(name)'
>  >  >                 )
>  >  >         );
>  >  >
>  >  >         $this->set('funders', $this->Fund->find('all', $criteria, 
> $fields));
>  >  >  }
>  >  >
>  >  >  For some reason beyond my ken, Cake isn't selecting on Discipline
>  >  >  (I've also tried adding it to the $fields array).
>  >  >
>  >  >  Can anyone point out out my error?
>  >  >
>  >  >
>  >  >  >  >  >
>  >  >
>  >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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