This is just a rough idea and will need to be completed (and probably
improved some), but hopefully it can get you started.

In AppModel:

var $schedule_id;

function find($conditions = null, $fields = array(), $order = null,
$recursive = null) {
  if (is_array($conditions)) {
    if (!array_key_exists('conditions', $conditions))
$conditions['conditions'] = array();
    $conditions['conditions']['schedule_id'] = $this->schedule_id;
  }
  else if (is_array($fields)) {
    if (!array_key_exists('conditions', $fields))
$fields['conditions'] = array();
    $fields['conditions']['schedule_id'] = $this->schedule_id;
  }

  return parent::find($conditions, $fields, $order, $recursive);
}

And then in your controller:

$this->Model->schedule_id = $schedule_id;
$result = $this->Model->find(...);

On May 22, 10:07 am, shantamg <[email protected]> wrote:
> @Andrel: I'd love to be able to set the conditions in the model, but
> the model can't know what's in the session!
>
> @Paul:
>
> > > $this->Person->contain('Hobby', 'Job');
>
> > I've never seen anyone set containable options like above, I thought
> > they had to be within the find options array
>
> http://book.cakephp.org/view/857/Containing-deeper-associations
>
> > I don't see how your conditions array can be set the same for every
> > model within your schema as I doubt every model is directly associated
> > to People for the conditions People.schedule_id to work.
>
> Every model is related to the Schedule model. So I was thinking of
> something like this in the appController:
>
> $this->{$model}->conditions->array('schedule_id' => $schedule_id);
>
> but i don't think that will work...
> Also, every related model has to be given those conditions in the
> containable:
>
> $this->[$model}->contain(
>     "{$related_model1}.schedule_id = $schedule_id",
>     "{$related_model2}.schedule_id = $schedule_id"
> );
>
> > And what about the finds where a user is not logged in/has not created
> > a session, they can't have a schedule_id set?
>
> No user has to be logged in. I am doing this in the appController:
>
> function beforeFilter() {
>     // put the latest published schedule into the session
>     if (!$this->Session->check('Schedule')) {
>         $schedule = ClassRegistry::init('Schedule')->find('first',
>                 array('order' => 'id desc')
>         );
>         $this->Session->write('Schedule', $schedule['Schedule']);
>     }
>
> }
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with 
> their CakePHP related questions.
>
> 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 
> athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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