#6222: HABTM tables not included in FROM clause when $fields used on Model->find
---------------------------+------------------------------------------------
    Reporter:  cuppett     |          Type:  Bug  
      Status:  new         |      Priority:  High 
   Milestone:  1.2.x.x     |     Component:  Model
     Version:  1.2 Final   |      Severity:  Major
    Keywords:              |   Php_version:  PHP 5
Cake_version:  1.2.2.8120  |  
---------------------------+------------------------------------------------
 PHP 5.2.9
 Database: PostgreSQL
 CakePHP: 1.2.2.8120

 When querying Models using the find() mechanism, it appears that
 regardless of setting recursive to 1 or 2, the HABTM tables are not
 included in the FROM clause when $fields is specified.  Here is the query:

                 $feature = $this->Feature->find(
                         "first",
                         array(
                                 "conditions" => array(
                                         "Feature.id" =>
 $testcase["Testcase"]["feature_id"]
                                 ),
                                 "recursive" => 1, //  For some reason this
 doesn't work with HABTM models.
                                 "fields" => array(
                                         "Feature.id",
                                         "Feature.tester_id",
                                         "Feature.release_id",
                                         "Feature.allow_any",
                                         "Editor.id",
                                         "Editor.feature_id"
                                 )
                         )
                 );

 Then the query generated looks like this:

 SELECT "Feature"."id" AS "Feature__id", "Feature"."tester_id" AS
 "Feature__tester_id", "Feature"."release_id" AS "Feature__release_id",
 "Feature"."allow_any" AS "Feature__allow_any", "Editor"."id" AS
 "Editor__id", "Editor"."feature_id" AS "Editor__feature_id" FROM
 "features" AS "Feature" LEFT JOIN "releases" AS "Release" ON
 ("Feature"."release_id" = "Release"."id") LEFT JOIN "users" AS "Tester" ON
 ("Feature"."tester_id" = "Tester"."id") WHERE "Feature"."id" = '113' LIMIT
 1

 With the following error:

 SQL Error: ERROR:  missing FROM-clause entry for table "Editor"
 LINE 1: ...", "Feature"."allow_any" AS "Feature__allow_any", "Editor"."...

 Normally, there is a second query issued for the HABTM Model, but that's
 not there, or we don't get there because of the error on the first query.

-- 
Ticket URL: <https://trac.cakephp.org/ticket/6222>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design 
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. 
Our primary goal is to provide a structured framework that enables PHP users at 
all levels to rapidly develop robust web applications, without any loss to 
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"tickets 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/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to