Have you tried : $this->Category->find(array('Product.project_id'=>
$this->Session->read('project_id')));

Geoff
--
http://lemoncake.wordpress.com

On Aug 10, 8:48 am, sarimarton <[EMAIL PROTECTED]> wrote:
> But you do have association between projects and products. You have
> the proper associations.
> Your problem is that you need runtime conditions. I had the same
> problem, ie. needed a condition which
> is cannot be described with the association scheme.
>
> You can't put runtime calculations (in this case project id depends on
> a session value)
> in the model's description file. (models/product.php,
> $belongsTo=>Project=>conditions=>"Project.id = ?")
>
> You could put the condition in the binding in AppModel's beforeFind():
>
> function beforeFind(&$queryData) {
>   if ($this->name == 'Project') $queryData['conditions'][] =
> 'Project.id = '.Session::read('projectid');
>   return $queryData;
>
> }
>
> But it's also is not a favourable way of it, because with beforeFind()
> you can't controll non-primary queries.
> So you would have to prepare for all the related finds:
>   if ($this->name == 'Product') $queryData['conditions'][] =
> 'Product.project_id = '.Session::read('projectid');
>   ...
>
> This works, however you simply can't list every case because of
> recursion. So if you query Categories it will
> include all projects.
>
> My next try was that somehow I need to set the association array
> member of the Product CLASS (not an instantiated
> object with $this->Product...) in my AppController's beforeFilter().
> This would look like this:
>
> Product::belongsTo['Project']['conditions'] = 'Project.id =
> '.Session::etc;
>
> But unfortunately the association members of the models are declared
> as 'var', not as 'static public', so you can't overwrite them.
>
> But fortunately :), there is an absolutely DRY solution for reaching
> the class and its offals:
>
>         $cr =& ClassRegistry::getInstance();
>         $cr->__objects['product']->belongsTo['Project']['conditions'] =
> 'Project.id = etc.';
>
> This way, you can set every associations and its conditions and other
> data runtime, just
> like it would be in the model file. So you can query any model, even a
> distant binded one
> (eg. Category), you will get your runtime created condition in the
> related queries. You can
> check it with DEBUG level 3.
>
> Cheers,
> Marci
>
> On Jul 24, 9:02 am, lgarcia <[EMAIL PROTECTED]> wrote:
>
> > But if i have not any association between categories and projects, how
> > i'll achieve my goal?
>
> > On 24 jul, 00:43, Grant Cox <[EMAIL PROTECTED]> wrote:
>
> > > You should temporarily bind the association with the required
> > > project_id, in the controller action.  There are a large number of
> > > ways of binding an association - using the inbuilt bindModel and
> > > unbindModel, the "useModel" function available on the bakery, or
> > > Felix's Containable behaviour (I haven't used this yet, but it looks
> >
> the most advanced)http://www.thinkingphp.org/2007/06/14/containable-20-beta/


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