Re: conditions with date in hasMany

2009-06-22 Thread brian

You shouldn't have conditions in there. You're describing an
association between 2 models, not options for eg. pagination. Jobs
that are  2 weeks old should still be associated with Recruiter (I'm
guessing is the other model).

Put those conditions in the controller's $paginate var or whatever
find() call you're making where you only want new Jobs.

On Mon, Jun 22, 2009 at 12:10 PM, abest11abhishe...@gmail.com wrote:

 Hi,
 Im a newbie to Cake, so apologies in advance if this is a silly
 question.  I am trying to use a simple hasMany model association with
 a condition on a date field, so that only Jobs created in the last
 two weeks are returned.  In my model, I have:

 var $hasMany = array(
        'Job' = array(
                'className' = 'Job',
                'foreignKey' = 'recruiter_id',
                'conditions' = array(Job.created  = date('Y-m-d', 
 strtotime(-2
 weeks))),
        )
 );

 This is based off the manual Complex Find Conditions topic.

 For some reason, I keep getting the error
 Parse error: syntax error, unexpected '.', expecting ')' for the
 line which defines the conditions...

 I can't seem to figure out whats wrong with my syntax. Im using the
 latest version of Cake.

 Thanks!


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



conditions with date in hasMany

2009-06-22 Thread abest11

Hi,
Im a newbie to Cake, so apologies in advance if this is a silly
question.  I am trying to use a simple hasMany model association with
a condition on a date field, so that only Jobs created in the last
two weeks are returned.  In my model, I have:

var $hasMany = array(
'Job' = array(
'className' = 'Job',
'foreignKey' = 'recruiter_id',
'conditions' = array(Job.created  = date('Y-m-d', 
strtotime(-2
weeks))),
)
);

This is based off the manual Complex Find Conditions topic.

For some reason, I keep getting the error
Parse error: syntax error, unexpected '.', expecting ')' for the
line which defines the conditions...

I can't seem to figure out whats wrong with my syntax. Im using the
latest version of Cake.

Thanks!


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: conditions with date in hasMany

2009-06-22 Thread abest11

I understand that I can specify conditions when I do a find call.
But I want it to filter the associated model automatically.

If I am misunderstanding, can you explain what the use of the
'conditions' key is in the hasMany association as described here
http://book.cakephp.org/view/82/hasMany

On Jun 22, 6:41 pm, brian bally.z...@gmail.com wrote:
 You shouldn't have conditions in there. You're describing an
 association between 2 models, not options for eg. pagination. Jobs
 that are  2 weeks old should still be associated with Recruiter (I'm
 guessing is the other model).

 Put those conditions in the controller's $paginate var or whatever
 find() call you're making where you only want new Jobs.



 On Mon, Jun 22, 2009 at 12:10 PM, abest11abhishe...@gmail.com wrote:

  Hi,
  Im a newbie to Cake, so apologies in advance if this is a silly
  question.  I am trying to use a simple hasMany model association with
  a condition on a date field, so that only Jobs created in the last
  two weeks are returned.  In my model, I have:

  var $hasMany = array(
         'Job' = array(
                 'className' = 'Job',
                 'foreignKey' = 'recruiter_id',
                 'conditions' = array(Job.created  = date('Y-m-d', 
  strtotime(-2
  weeks))),
         )
  );

  This is based off the manual Complex Find Conditions topic.

  For some reason, I keep getting the error
  Parse error: syntax error, unexpected '.', expecting ')' for the
  line which defines the conditions...

  I can't seem to figure out whats wrong with my syntax. Im using the
  latest version of Cake.

  Thanks!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: conditions with date in hasMany

2009-06-22 Thread brian

On Mon, Jun 22, 2009 at 12:44 PM, abest11abhishe...@gmail.com wrote:

 I understand that I can specify conditions when I do a find call.
 But I want it to filter the associated model automatically.

 If I am misunderstanding, can you explain what the use of the
 'conditions' key is in the hasMany association as described here
 http://book.cakephp.org/view/82/hasMany

It's just what you thought it was. That's new to me. It's not
something that makes any sense to me because the status of a Comment
or the date that a Job was created should not, IMHO, be the basis for
filtering an association between models. Personally, I think that,
while it may be a shortcut, it's wrong to filter like that in the
association. I guess the Cake devs feel otherwise.

So, ignore my other comment, if you like.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---