Hello,

I am trying to use findAll to grab data from 2 tables that are linked
by a HasMany and BelongTo association. I wounder if it's possible or if
I have to do a query statement.

I am writing a B2B application, basically 2 models, 2 tables :

An application table and an offer table, an application has many offer
and an offer belong to an application:

Application table and model :

   class Application extends AppModel
   {
      var $name      = 'Application'; // required for php4 installs

      var $hasMany   = array(
                             'Offer' =>
                          array('className'   => 'Offer',
                                'conditions'  => '',
                                'order'       => 'Offer.created ASC',
                                'limit'       => '',
                                'foreignKey'  => 'Application_id',
                                'dependent'   => true,
                                'exclusive'   => true,
                                'finderSql'   => '')
                        );
  }

   class Offer extends AppModel
   {
      var $name      = 'Offer'; // required for php4 installs
      var $belongsTo = array('Application' =>
                                 array('className'  => 'Application',
                                       'conditions' => '',
                                       'order'      => '',
                                       'foreignKey' =>
'application_id'));
   }

So far ok, now depending on the user logged on and it's role (can be
seen as an Auction business) :
- one user creates an application
- other user make offers for it

My problem is when a "user" as a role of Offering side, I want to be
able to select all applications that is has not yet make an offer, or
select only application that he has made offer (a field user_id is in
both table and in the following example $this->c_user is retreived from
the Session object and matches the current user) :

- means select all application that have no offer for this user_id
$cond = 'appstate = 1 OR (appstate = 2 AND Offer.user_id !=
'.$this->c_user.')'

(appstate is just the state of the application does not matter
really)..

I have turned debug to 2 and seen my select statement, and of course
the table Offer is not in the searched table list, so It comes up with
an "unknow table offer" ..
I also like the findAll because I have set pagination with it ...

What the best way to do this ? Should I use a "query" statement ? But
my pagination will have to we worked again ...

Thanks for your advises


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to