Re: Contain() or INNER JOIN

2009-08-20 Thread Long
I did it! q:D

Вроде получилось.

Решение:

$data = $this->Site->Job->find(
'all',
array (
   'recursive'   => 1,
'fields'=> array('DISTINCT Job.date'),
'conditions' => array('Job.site_id' => 3),
'contain' => array (
'JobComment' => array(
'fields' => array (
 'JobComment.comment',
 'JobComment.created',
 'JobComment.whois'),
'conditions' => array (
'JobComment.trouble' => 1)
 )
   ),
   'joins' => array(
array(
'table' => 'job_comments',
'alias' => 'JobComment',
'type' => 'INNER',
'foreignKey' => false,
'conditions'=> array(
'JobComment.job_id = Job.id',
'JobComment.trouble = 1'
)
)
 )
));

On 19 авг, 17:37, Long  wrote:
> Thanks for the reply
>
> I have changed my app_model.php to (http://bakery.cakephp.org/articles/
> view/quick-tip-doing-ad-hoc-joins-in-model-find) code.
> How can i use the new FIND() method?
>
> $this->Site->find ('matches', array (
>       'model'     => array ('Job'),
>            'scope'     => array (
>                   'Area'      => array ('Site.id'  => 3),
>                   )
>                )
>             );
>
> Isn't it?
>
> On 19 авг, 17:02, Martin Westin  wrote:
>
>
>
> > You are right (in the subject), you need a join.
> > You can force Cake to do joins if you build something like what Nate
> > wrote about in january:
>
> >http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-...
>
> > I took some ideas from that and made a joining feature that would join
> > models for me when needed, using a very similar syntax to Containable
> > (often interchangeable).
>
> >http://bin.cakephp.org/saved/49446
>
> > I have linked to these before (twice in the last 24hrs). I am not
> > doing it to spam the group, honestly.
>
> >http://groups.google.com/group/cake-php/browse_thread/thread/3e6644c9..
>
> > hope you find it useful.
>
> > On Aug 19, 2:26 pm, Long  wrote:
>
> > > Update:
>
> > > 3 models:
> > > sites hasMany jobs
> > > jobs belongsTo sites
>
> > > jobs hasMany job_comments
> > > job_comments belongsTo jobs
>
> > > Site->Job->JobComment
>
> > > $this->Site->find( 'all',
> > > array('fields'=>array('Site.id'),
> > >     'conditions' =>array(
> > >         'Site.id' => 3),
> > >     'contain' => array (
> > >         'Job' => array(
> > >              'conditions' => array (
> > >                  'Job.site_id' => 3),
> > >                  'JobComment' => array (
> > >                       'fields' => array (
> > >                           'JobComment.comment'),
> > >                       'conditions' => array (
> > >                           'JobComment.trouble' => 1
> > >                                                     )
> > >                                                   )
> > >                                                 )
> > >                                               )
> > >                                             )
> > >                                         ));
>
> > > On 19 авг, 16:17, Long  wrote:
>
> > > > Greetings!
>
> > > > I have 3 models:
>
> > > > jobs hasMany job_comments
> > > > job_comments belongsTo jobs
>
> > > > Site->Job->JobComment
>
> > > > Help me please to find works on a site which have 'trouble' comments
>
> > > > $this->Site->find( 'all', array (  'fields'    => array('Site.id'),
> > > >                                             'conditions' => array
> > > > ('Site.id' => 3),
> > > >                                             'contain' => array (
> > > >                                             'Job' => array(
> > > >                                                         'conditions'
> > > > => array ('Job.site_id' => 3),
> > > >                                                         'JobComment'
> > > > => array (
> > > >                                                         'fields' =>
> > > > array ('JobComment.comment'),
>
> > > > 'conditions' => array (
>
> > > > 'JobComment.trouble' => 1
> > > >                                                                         
> > > >  )
> > > >                                                                )
> > > >                                                          )
> > > >                                                    )
> > > >                                             )
> > > >                                         ));
>
> > > > ...It doesn't work good.
> > > > I no need all Jobs on site. I nee

Re: Contain() or INNER JOIN

2009-08-19 Thread Long
Thanks for the reply

I have changed my app_model.php to (http://bakery.cakephp.org/articles/
view/quick-tip-doing-ad-hoc-joins-in-model-find) code.
How can i use the new FIND() method?

$this->Site->find ('matches', array (
  'model' => array ('Job'),
   'scope' => array (
  'Area'  => array ('Site.id'  => 3),
  )
   )
);

Isn't it?

On 19 авг, 17:02, Martin Westin  wrote:
> You are right (in the subject), you need a join.
> You can force Cake to do joins if you build something like what Nate
> wrote about in january:
>
> http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-...
>
> I took some ideas from that and made a joining feature that would join
> models for me when needed, using a very similar syntax to Containable
> (often interchangeable).
>
> http://bin.cakephp.org/saved/49446
>
> I have linked to these before (twice in the last 24hrs). I am not
> doing it to spam the group, honestly.
>
> http://groups.google.com/group/cake-php/browse_thread/thread/3e6644c9...http://groups.google.com/group/cake-php/browse_thread/thread/43b4a9fc...
>
> hope you find it useful.
>
> On Aug 19, 2:26 pm, Long  wrote:
>
>
>
> > Update:
>
> > 3 models:
> > sites hasMany jobs
> > jobs belongsTo sites
>
> > jobs hasMany job_comments
> > job_comments belongsTo jobs
>
> > Site->Job->JobComment
>
> > $this->Site->find( 'all',
> > array('fields'=>array('Site.id'),
> >     'conditions' =>array(
> >         'Site.id' => 3),
> >     'contain' => array (
> >         'Job' => array(
> >              'conditions' => array (
> >                  'Job.site_id' => 3),
> >                  'JobComment' => array (
> >                       'fields' => array (
> >                           'JobComment.comment'),
> >                       'conditions' => array (
> >                           'JobComment.trouble' => 1
> >                                                     )
> >                                                   )
> >                                                 )
> >                                               )
> >                                             )
> >                                         ));
>
> > On 19 авг, 16:17, Long  wrote:
>
> > > Greetings!
>
> > > I have 3 models:
>
> > > jobs hasMany job_comments
> > > job_comments belongsTo jobs
>
> > > Site->Job->JobComment
>
> > > Help me please to find works on a site which have 'trouble' comments
>
> > > $this->Site->find( 'all', array (  'fields'    => array('Site.id'),
> > >                                             'conditions' => array
> > > ('Site.id' => 3),
> > >                                             'contain' => array (
> > >                                             'Job' => array(
> > >                                                         'conditions'
> > > => array ('Job.site_id' => 3),
> > >                                                         'JobComment'
> > > => array (
> > >                                                         'fields' =>
> > > array ('JobComment.comment'),
>
> > > 'conditions' => array (
>
> > > 'JobComment.trouble' => 1
> > >                                                                          )
> > >                                                                )
> > >                                                          )
> > >                                                    )
> > >                                             )
> > >                                         ));
>
> > > ...It doesn't work good.
> > > I no need all Jobs on site. I need only Jobs which have
> > > JobComment.trouble = 1
>
> > > Thx.
--~--~-~--~~~---~--~~
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: Contain() or INNER JOIN

2009-08-19 Thread Martin Westin
You are right (in the subject), you need a join.
You can force Cake to do joins if you build something like what Nate
wrote about in january:

http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-in-model-find

I took some ideas from that and made a joining feature that would join
models for me when needed, using a very similar syntax to Containable
(often interchangeable).

http://bin.cakephp.org/saved/49446

I have linked to these before (twice in the last 24hrs). I am not
doing it to spam the group, honestly.

http://groups.google.com/group/cake-php/browse_thread/thread/3e6644c906fbc656
http://groups.google.com/group/cake-php/browse_thread/thread/43b4a9fcc18cf442

hope you find it useful.


On Aug 19, 2:26 pm, Long  wrote:
> Update:
>
> 3 models:
> sites hasMany jobs
> jobs belongsTo sites
>
> jobs hasMany job_comments
> job_comments belongsTo jobs
>
> Site->Job->JobComment
>
> $this->Site->find( 'all',
> array('fields'=>array('Site.id'),
>     'conditions' =>array(
>         'Site.id' => 3),
>     'contain' => array (
>         'Job' => array(
>              'conditions' => array (
>                  'Job.site_id' => 3),
>                  'JobComment' => array (
>                       'fields' => array (
>                           'JobComment.comment'),
>                       'conditions' => array (
>                           'JobComment.trouble' => 1
>                                                     )
>                                                   )
>                                                 )
>                                               )
>                                             )
>                                         ));
>
> On 19 авг, 16:17, Long  wrote:
>
>
>
> > Greetings!
>
> > I have 3 models:
>
> > jobs hasMany job_comments
> > job_comments belongsTo jobs
>
> > Site->Job->JobComment
>
> > Help me please to find works on a site which have 'trouble' comments
>
> > $this->Site->find( 'all', array (  'fields'    => array('Site.id'),
> >                                             'conditions' => array
> > ('Site.id' => 3),
> >                                             'contain' => array (
> >                                             'Job' => array(
> >                                                         'conditions'
> > => array ('Job.site_id' => 3),
> >                                                         'JobComment'
> > => array (
> >                                                         'fields' =>
> > array ('JobComment.comment'),
>
> > 'conditions' => array (
>
> > 'JobComment.trouble' => 1
> >                                                                          )
> >                                                                )
> >                                                          )
> >                                                    )
> >                                             )
> >                                         ));
>
> > ...It doesn't work good.
> > I no need all Jobs on site. I need only Jobs which have
> > JobComment.trouble = 1
>
> > Thx.
--~--~-~--~~~---~--~~
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: Contain() or INNER JOIN

2009-08-19 Thread Long
Update:

3 models:
sites hasMany jobs
jobs belongsTo sites

jobs hasMany job_comments
job_comments belongsTo jobs

Site->Job->JobComment

$this->Site->find( 'all',
array('fields'=>array('Site.id'),
'conditions' =>array(
'Site.id' => 3),
'contain' => array (
'Job' => array(
 'conditions' => array (
 'Job.site_id' => 3),
 'JobComment' => array (
  'fields' => array (
  'JobComment.comment'),
  'conditions' => array (
  'JobComment.trouble' => 1
)
  )
)
  )
)
));


On 19 авг, 16:17, Long  wrote:
> Greetings!
>
> I have 3 models:
>
> jobs hasMany job_comments
> job_comments belongsTo jobs
>
> Site->Job->JobComment
>
> Help me please to find works on a site which have 'trouble' comments
>
> $this->Site->find( 'all', array (  'fields'    => array('Site.id'),
>                                             'conditions' => array
> ('Site.id' => 3),
>                                             'contain' => array (
>                                             'Job' => array(
>                                                         'conditions'
> => array ('Job.site_id' => 3),
>                                                         'JobComment'
> => array (
>                                                         'fields' =>
> array ('JobComment.comment'),
>
> 'conditions' => array (
>
> 'JobComment.trouble' => 1
>                                                                          )
>                                                                )
>                                                          )
>                                                    )
>                                             )
>                                         ));
>
> ...It doesn't work good.
> I no need all Jobs on site. I need only Jobs which have
> JobComment.trouble = 1
>
> Thx.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Contain() or INNER JOIN

2009-08-19 Thread Long

Greetings!

I have 3 models:

jobs hasMany job_comments
job_comments belongsTo jobs

Site->Job->JobComment

Help me please to find works on a site which have 'trouble' comments

$this->Site->find( 'all', array (  'fields'=> array('Site.id'),
'conditions' => array
('Site.id' => 3),
'contain' => array (
'Job' => array(
'conditions'
=> array ('Job.site_id' => 3),
'JobComment'
=> array (
'fields' =>
array ('JobComment.comment'),
 
'conditions' => array (
 
'JobComment.trouble' => 1
 )
   )
 )
   )
)
));

...It doesn't work good.
I no need all Jobs on site. I need only Jobs which have
JobComment.trouble = 1

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