I'm trying to find all Posts within a given range of dates (the month of February 2007 in this example), and I can't figure it out.
This isn't returning any results: $conditions['Post.created'] = array('>= 2007-02-01', '<= 2007-02-28'); $this->Post->findAll($conditions);
The strange part is that this works: $conditions['Post.created'] = '>= 2007-02-01'; $this->Post->findAll($conditions);
And so does this: $conditions['Post.created'] = '<= 2007-02-31'; $this->Post->findAll($conditions);
And so does this, assuming that posts exist on both those days, and it only returns posts on those days: $conditions['Post.created'] = array('2007-02-01', 2007-02-31'); $this->Post->findAll($conditions);
It also works if I query the database directly like this: select * from posts where created >= '2007-02-01' && created <= '2007-02-31';
> I'm trying to find all Posts within a given range of dates (the month > of February 2007 in this example), and I can't figure it out.
> This isn't returning any results: > $conditions['Post.created'] = array('>= 2007-02-01', '<= 2007-02-28'); > $this->Post->findAll($conditions);
> The strange part is that this works: > $conditions['Post.created'] = '>= 2007-02-01'; > $this->Post->findAll($conditions);
> And so does this: > $conditions['Post.created'] = '<= 2007-02-31'; > $this->Post->findAll($conditions);
> And so does this, assuming that posts exist on both those days, and it > only returns posts on those days: > $conditions['Post.created'] = array('2007-02-01', 2007-02-31'); > $this->Post->findAll($conditions);
> It also works if I query the database directly like this: > select * from posts where created >= '2007-02-01' && created <= > '2007-02-31';
I figured it out. I did this: $conditions[]['Post.created'] = '>= 2007-02-01'; $conditions[]['Post.created'] = '<= 2007-02-28'; $this->Post->find($conditions);
It seems the complex conditions section in the model chapter in the CakePHP Manual was wrong. It seems as Cake continues, the manual just seems older and older. Oh well, Cake still rocks.
On Feb 28, 4:13 pm, "BlenderStyle" <BlenderSt...@gmail.com> wrote:
> It's worth noting that this isn't working either: > $conditions['Post.id'] = array('>= 1', '<= 10'); > $this->Post->findAll($conditions);
> I think I don't understand how Cake deals with these ranges.
> On Feb 28, 4:10 pm, "BlenderStyle" <BlenderSt...@gmail.com> wrote:
> > I'm trying to find all Posts within a given range of dates (the month > > of February 2007 in this example), and I can't figure it out.
> > This isn't returning any results: > > $conditions['Post.created'] = array('>= 2007-02-01', '<= 2007-02-28'); > > $this->Post->findAll($conditions);
> > The strange part is that this works: > > $conditions['Post.created'] = '>= 2007-02-01'; > > $this->Post->findAll($conditions);
> > And so does this: > > $conditions['Post.created'] = '<= 2007-02-31'; > > $this->Post->findAll($conditions);
> > And so does this, assuming that posts exist on both those days, and it > > only returns posts on those days: > > $conditions['Post.created'] = array('2007-02-01', 2007-02-31'); > > $this->Post->findAll($conditions);
> > It also works if I query the database directly like this: > > select * from posts where created >= '2007-02-01' && created <= > > '2007-02-31';
> > Am I missing somthing? Why isn't this working?
I figured it out. I did this: $conditions[]['Post.created'] = '>= 2007-02-01'; $conditions[]['Post.created'] = '<= 2007-02-28'; $this->Post->find($conditions);
It seems the complex conditions section in the model chapter in the CakePHP Manual was wrong. It seems as Cake continues, the manual just seems older and older. Oh well, Cake still rocks.
On Feb 28, 4:13 pm, "BlenderStyle" <BlenderSt...@gmail.com> wrote:
> It's worth noting that this isn't working either: > $conditions['Post.id'] = array('>= 1', '<= 10'); > $this->Post->findAll($conditions);
> I think I don't understand how Cake deals with these ranges.
> On Feb 28, 4:10 pm, "BlenderStyle" <BlenderSt...@gmail.com> wrote:
> > I'm trying to find all Posts within a given range of dates (the month > > of February 2007 in this example), and I can't figure it out.
> > This isn't returning any results: > > $conditions['Post.created'] = array('>= 2007-02-01', '<= 2007-02-28'); > > $this->Post->findAll($conditions);
> > The strange part is that this works: > > $conditions['Post.created'] = '>= 2007-02-01'; > > $this->Post->findAll($conditions);
> > And so does this: > > $conditions['Post.created'] = '<= 2007-02-31'; > > $this->Post->findAll($conditions);
> > And so does this, assuming that posts exist on both those days, and it > > only returns posts on those days: > > $conditions['Post.created'] = array('2007-02-01', 2007-02-31'); > > $this->Post->findAll($conditions);
> > It also works if I query the database directly like this: > > select * from posts where created >= '2007-02-01' && created <= > > '2007-02-31';
> > Am I missing somthing? Why isn't this working?
I figured it out. I did this: $conditions[]['Post.created'] = '>= 2007-02-01'; $conditions[]['Post.created'] = '<= 2007-02-28'; $this->Post->find($conditions);
It seems the complex conditions section in the model chapter in the CakePHP Manual was wrong. It seems as Cake continues, the manual just seems older and older. Oh well, Cake still rocks.
On Feb 28, 4:13 pm, "BlenderStyle" <BlenderSt...@gmail.com> wrote:
> It's worth noting that this isn't working either: > $conditions['Post.id'] = array('>= 1', '<= 10'); > $this->Post->findAll($conditions);
> I think I don't understand how Cake deals with these ranges.
> On Feb 28, 4:10 pm, "BlenderStyle" <BlenderSt...@gmail.com> wrote:
> > I'm trying to find all Posts within a given range of dates (the month > > of February 2007 in this example), and I can't figure it out.
> > This isn't returning any results: > > $conditions['Post.created'] = array('>= 2007-02-01', '<= 2007-02-28'); > > $this->Post->findAll($conditions);
> > The strange part is that this works: > > $conditions['Post.created'] = '>= 2007-02-01'; > > $this->Post->findAll($conditions);
> > And so does this: > > $conditions['Post.created'] = '<= 2007-02-31'; > > $this->Post->findAll($conditions);
> > And so does this, assuming that posts exist on both those days, and it > > only returns posts on those days: > > $conditions['Post.created'] = array('2007-02-01', 2007-02-31'); > > $this->Post->findAll($conditions);
> > It also works if I query the database directly like this: > > select * from posts where created >= '2007-02-01' && created <= > > '2007-02-31';
> > Am I missing somthing? Why isn't this working?
On Mar 1, 4:18 am, "BlenderStyle" <BlenderSt...@gmail.com> wrote:
> I figured it out. I did this: > $conditions[]['Post.created'] = '>= 2007-02-01'; > $conditions[]['Post.created'] = '<= 2007-02-28'; > $this->Post->find($conditions);
> It seems the complex conditions section in the model chapter in the > CakePHP Manual was wrong. It seems as Cake continues, the manual just > seems older and older. Oh well, Cake still rocks.
There is no error in the manual wrt to how to generate array constraints; I think there is a simple misunderstanding.
$conditions['Post.created'] = array('>= 2007-02-01', '<= 2007-02-28'); will generate ... WHERE `Post`.`created` IN ('>= 2007-02-01', '<= 2007-02-28') ... which is obviously not what you wanted. using an array in that manner ONLY generates an IN statemnet, it isn't used to build a list of conditions to apply to the same field, where in the manual does it suggest this will work?
There are several alternatives to the final solution you found (just for info) 1) $conditions['Post.created'] = '>= 2007-02-01'; $conditions[]['Post.created'] = '<= 2007-02-28'; The only reason the extra array (or arrays in your solution) are needed is because otherwise you would overwrite one condition with another.
2) $conditions['Post.created'] = 'BETWEEN 2007-02-01 AND 2007-02-28'; (iirc)
> On Mar 1, 4:18 am, "BlenderStyle" <BlenderSt...@gmail.com> wrote:
> > I figured it out. I did this: > > $conditions[]['Post.created'] = '>= 2007-02-01'; > > $conditions[]['Post.created'] = '<= 2007-02-28'; > > $this->Post->find($conditions);
> > It seems the complex conditions section in the model chapter in the > > CakePHP Manual was wrong. It seems as Cake continues, the manual just > > seems older and older. Oh well, Cake still rocks.
> There is no error in the manual wrt to how to generate array > constraints; I think there is a simple misunderstanding.
> $conditions['Post.created'] = array('>= 2007-02-01', '<= > 2007-02-28'); > will generate > ... WHERE `Post`.`created` IN ('>= 2007-02-01', '<= 2007-02-28') ... > which is obviously not what you wanted. using an array in that manner > ONLY generates an IN statemnet, it isn't used to build a list of > conditions to apply to the same field, where in the manual does it > suggest this will work?
> There are several alternatives to the final solution you found (just > for info) > 1) > $conditions['Post.created'] = '>= 2007-02-01'; > $conditions[]['Post.created'] = '<= 2007-02-28'; > The only reason the extra array (or arrays in your solution) are > needed is because otherwise you would overwrite one condition with > another.