Re: Error on find on hasAndBelongsToMany relationed models

2013-04-26 Thread Saran Pal
Dear Ciul,

As *Reuben* said  HABTM generally doesn't do a join, but if you want to
joins then you will need to set up an extra table in the database to handle
this relationship.

For more details you can visit here -
http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#hasandbelongstomany-habtm

Cheers!..

Saran


On Thu, Apr 25, 2013 at 5:49 PM, Reuben reuben.he...@gmail.com wrote:

 The HABTM generally doesn't do a join.  You would only use a straight find
 when you have conditions for only one of the models.

 Alternatives are to use contains, or use join to explicitly define the
 join and the join conditions.  Whilst contains is handy, I usually end up
 going with the join clause, because it matches mostly closely with what I'd
 do, if I was writing straight SQL.

 Regards
 Reuben Helms


 On Thursday, 25 April 2013 02:47:31 UTC+10, Ciul wrote:

 I'm having troubles to restrict a find operation based on a related model
 field within a hasAndBelongsToMany relationship.

 *// Wedding Model*
 *public $hasAndBelongsToMany = array('Guest');*
 *
 *
 *// Guest Model*
 *public $hasAndBelongsToMany = array('Wedding');*
 *
 *
 *Then, calling in Guest Controller:*
 *
 *
 *// GuestsController Controller*
 *$this-Guest-find('first', array(*
 *  'conditions' = array(*
 *  **  **'Guest.email' = 'te...@test.com',*
 *  **  **'Wedding.alias' = 'maria-wedding'*
 *  **),*
 *  **'recursive' = 1*
 *);*


 *ERROR:*

 Column not found: 1054 Unknown column 'Wedding.alias' in 'where clause'

 *SQL Query: *SELECT `Guest`.`id`, `Guest`.`created`, `Guest`.`modified`,
 `Guest`.`name`, `Guest`.`email`, `Guest`.`enabled`, `Guest`.`confirmed`

 FROM `weddingshare`.`demo_guests` AS `Guest` WHERE `Guest`.`email` = '
 te...@test.com' AND `Wedding`.`alias` = 'maria-wedding' LIMIT 1

 I understand it is not event joining tables to make the request.

 Please, I'd appreciate any help.

 Regards

  --
 Like Us on FaceBook https://www.facebook.com/CakePHP
 Find us on Twitter http://twitter.com/CakePHP

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




-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

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




Re: Error on find on hasAndBelongsToMany relationed models

2013-04-25 Thread Reuben
The HABTM generally doesn't do a join.  You would only use a straight find 
when you have conditions for only one of the models.  

Alternatives are to use contains, or use join to explicitly define the join 
and the join conditions.  Whilst contains is handy, I usually end up going 
with the join clause, because it matches mostly closely with what I'd do, 
if I was writing straight SQL.

Regards
Reuben Helms

On Thursday, 25 April 2013 02:47:31 UTC+10, Ciul wrote:

 I'm having troubles to restrict a find operation based on a related model 
 field within a hasAndBelongsToMany relationship.

 *// Wedding Model*
 *public $hasAndBelongsToMany = array('Guest');*
 *
 *
 *// Guest Model*
 *public $hasAndBelongsToMany = array('Wedding');*
 *
 *
 *Then, calling in Guest Controller:*
 *
 *
 *// GuestsController Controller*
 *$this-Guest-find('first', array(*
 *  'conditions' = array(*
 *  **  **'Guest.email' = 'te...@test.com javascript:',*
 *  **  **'Wedding.alias' = 'maria-wedding'*
 *  **),*
 *  **'recursive' = 1*
 *);*


 *ERROR:*

 Column not found: 1054 Unknown column 'Wedding.alias' in 'where clause'

 *SQL Query: *SELECT `Guest`.`id`, `Guest`.`created`, `Guest`.`modified`, 
 `Guest`.`name`, `Guest`.`email`, `Guest`.`enabled`, `Guest`.`confirmed`

 FROM `weddingshare`.`demo_guests` AS `Guest` WHERE `Guest`.`email` = '
 te...@test.com javascript:' AND `Wedding`.`alias` = 'maria-wedding' 
 LIMIT 1

 I understand it is not event joining tables to make the request.

 Please, I'd appreciate any help.

 Regards


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

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




Error on find on hasAndBelongsToMany relationed models

2013-04-24 Thread Ciul
I'm having troubles to restrict a find operation based on a related model 
field within a hasAndBelongsToMany relationship.

*// Wedding Model*
*public $hasAndBelongsToMany = array('Guest');*
*
*
*// Guest Model*
*public $hasAndBelongsToMany = array('Wedding');*
*
*
*Then, calling in Guest Controller:*
*
*
*// GuestsController Controller*
*$this-Guest-find('first', array(*
*  'conditions' = array(*
*  **  **'Guest.email' = 't...@test.com',*
*  **  **'Wedding.alias' = 'maria-wedding'*
*  **),*
*  **'recursive' = 1*
*);*


*ERROR:*

Column not found: 1054 Unknown column 'Wedding.alias' in 'where clause'

*SQL Query: *SELECT `Guest`.`id`, `Guest`.`created`, `Guest`.`modified`, 
`Guest`.`name`, `Guest`.`email`, `Guest`.`enabled`, `Guest`.`confirmed`

FROM `weddingshare`.`demo_guests` AS `Guest` WHERE `Guest`.`email` = 
't...@test.com' AND `Wedding`.`alias` = 'maria-wedding' LIMIT 1

I understand it is not event joining tables to make the request.

Please, I'd appreciate any help.

Regards

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

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




Find with $hasAndBelongsToMany

2011-05-30 Thread hill180
I have three models
Authors
Books (hasandbelongstomany category)
Category

They are properly configured for $hasAndBelongsToMany (books/category)
relationship.

I need to get all books by an author in a certain category (5 in this
example)

Obviously the category id is not in the authors table so I am trying to
figure out how to reference the category id.  I have tried below to no
avail.

$this-Category-Author-find('all',
array('conditions'=array('Category.id'='5', 'Author.id'='2')));
or
$this-Author-find('all', array('conditions'=array('Category.id'='5',
'Author.id'='2')));

This is the first time I have done a HABTM query.  (searched manual and and
a couple cake books - no help)

Thanks!

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Find with $hasAndBelongsToMany

2011-05-30 Thread Shaz
I've just posted a similiar query!

Googling around has given me the bindModel() method - which you can
read at the bottom of the page here:

http://book.cakephp.org/view/1044/hasAndBelongsToMany-HABTM

But I wasn't able to get it to work for me. There's also a method
using manual joins and creating models for the join table and querying
it - haven't tried either of the two and can't say if they'll work.

On May 30, 5:14 pm, hill180 hill...@gmail.com wrote:
 I have three models
 Authors
 Books (hasandbelongstomany category)
 Category

 They are properly configured for $hasAndBelongsToMany (books/category)
 relationship.

 I need to get all books by an author in a certain category (5 in this
 example)

 Obviously the category id is not in the authors table so I am trying to
 figure out how to reference the category id.  I have tried below to no
 avail.

 $this-Category-Author-find('all',
 array('conditions'=array('Category.id'='5', 'Author.id'='2')));
 or
 $this-Author-find('all', array('conditions'=array('Category.id'='5',
 'Author.id'='2')));

 This is the first time I have done a HABTM query.  (searched manual and and
 a couple cake books - no help)

 Thanks!

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Find with $hasAndBelongsToMany

2011-05-30 Thread hill180
I saw that page in the manual, but glanced over the answer.  Thanks!

Shaz, this is what I did to solve the problem if you are still having
problems.

$this-Author-bindModel(array(
'hasAndBelongsToMany' = array(
'Category' = array('conditions'=array('Category.id'='5'))
)));
$this-Author-find('all', array('conditions'=array('Author.id'='2')));

On Mon, May 30, 2011 at 1:06 PM, Shaz shazam...@gmail.com wrote:

 I've just posted a similiar query!

 Googling around has given me the bindModel() method - which you can
 read at the bottom of the page here:

 http://book.cakephp.org/view/1044/hasAndBelongsToMany-HABTM

 But I wasn't able to get it to work for me. There's also a method
 using manual joins and creating models for the join table and querying
 it - haven't tried either of the two and can't say if they'll work.

 On May 30, 5:14 pm, hill180 hill...@gmail.com wrote:
  I have three models
  Authors
  Books (hasandbelongstomany category)
  Category
 
  They are properly configured for $hasAndBelongsToMany (books/category)
  relationship.
 
  I need to get all books by an author in a certain category (5 in this
  example)
 
  Obviously the category id is not in the authors table so I am trying to
  figure out how to reference the category id.  I have tried below to no
  avail.
 
  $this-Category-Author-find('all',
  array('conditions'=array('Category.id'='5', 'Author.id'='2')));
  or
  $this-Author-find('all', array('conditions'=array('Category.id'='5',
  'Author.id'='2')));
 
  This is the first time I have done a HABTM query.  (searched manual and
 and
  a couple cake books - no help)
 
  Thanks!

 --
 Our newest site for the community: CakePHP Video Tutorials
 http://tv.cakephp.org
 Check out the new CakePHP Questions site http://ask.cakephp.org and help
 others with their CakePHP related questions.


 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


-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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