#5268: Associations between models for tables in different schemas fails for
PostGRES tables
-------------------------+--------------------------------------------------
    Reporter:  jazztini  |         Owner:          
        Type:  Bug       |        Status:  reopened
    Priority:  Medium    |     Milestone:  1.2.x.x 
   Component:  General   |       Version:  RC2     
    Severity:  Normal    |    Resolution:          
    Keywords:            |   Php_version:  n/a     
Cake_version:            |  
-------------------------+--------------------------------------------------
Changes (by antonio__marco):

  * status:  closed => reopened
  * resolution:  invalid =>

Comment:

 Hi folks![[BR]][[BR]]

 I want to reopen this ticket specifically because the
 '''hasAndBelongsToMany''' association that '''do not works''' when the
 tables are in '''DIFFERENT SCHEMAS'''.[[BR]][[BR]]

 I'm building many different applications that will access data whose
 tables are in different PostgreSQL schemas, in the same
 database.[[BR]][[BR]]

 I has a situation as show bellow.[[BR]][[BR]]

 DB tables:

 {{{
 -- SCHEMA: dme
 CREATE TABLE dme.addresses
 (
   id                    serial       NOT NULL,
   created               timestamp,
   modified              timestamp,
   habilitado            bool         NOT NULL DEFAULT true,
   street_postal_code_id int          NOT NULL,
   parent_id             int,
   complemento           bool         NOT NULL DEFAULT false,
   numero                smallint,
   bloco                 varchar(10),
   andar                 smallint,
   unidade               smallint,
   posicao               smallint,
   caixa_postal          smallint,
   complemento_livre     varchar(255),

   PRIMARY KEY (id),

   FOREIGN KEY (street_postal_code_id) REFERENCES dme.street_postal_codes
 (id),
   FOREIGN KEY (parent_id) REFERENCES dme.addresses (id)
 )
 WITH OIDS;

 -- SCHEMA: geo
 CREATE TABLE geo.plots
 (
   id                          serial       NOT NULL,
   created                     timestamp,
   modified                    timestamp,

   inscricao_imobiliaria       varchar(14)  NOT NULL,
   quadra                      varchar(10),
   lote                        smallint,
   numero_residencial_previo   smallint,

   PRIMARY KEY (id)
 )
 WITH OIDS;

 -- SCHEMA: geo
 CREATE TABLE geo.addresses_plots
 (
   id                          serial       NOT NULL,
   created                     timestamp,
   modified                    timestamp,

   plot_id                     int          NOT NULL,
   address_id                  int          NOT NULL,
   endereco_principal          bool         NOT NULL DEFAULT true,

   PRIMARY KEY (id),
   FOREIGN KEY (plot_id) REFERENCES geo.plots (id),
   FOREIGN KEY (address_id) REFERENCES dme.addresses (id)
 )
 WITH OIDS;
 }}}

 CakePHP configuration:

 {{{
 // database.php
 class DATABASE_CONFIG {
         var $dme = array(
                 'driver'     => 'postgres',
                 'persistent' => false,
                 'host'       => 'localhost',
                 'port'       => '5432',
                 'login'      => 'postgres',
                 'password'   => '',
                 'database'   => 'pmsc_local',
                 'schema'     => 'dme',
                 'prefix'     => '',
                 'encoding'   => 'UTF8'
         );

         var $geo = array(
                 'driver'     => 'postgres',
                 'persistent' => false,
                 'host'       => 'localhost',
                 'port'       => '5432',
                 'login'      => 'postgres',
                 'password'   => '',
                 'database'   => 'pmsc_local',
                 'schema'     => 'geo',
                 'prefix'     => '',
                 'encoding'   => 'UTF8'
         );
 }
 }}}

 Models:

 {{{
 // address.php
 class Address extends AppModel {
         var $name = 'Address';

         var $useDbConfig = 'dme';
 }

 // plot.php
 class Plot extends AppModel {
         var $name = 'Plot';

         var $useDbConfig = 'geo';

         var $hasAndBelongsToMany = array(
                 'Address' => array(
                         'className'  => 'Address',
                         'foreignKey' => 'plot_id',
                         'associationForeignKey' => 'address_id',
                         'conditions' => 'Address.complemento = false'
                 )
         );
 }
 }}}

 Controllers (I'm using Scaffolding for tests):[[BR]][[BR]]

 So, when I run Plot's ''index'' everything is fine. But when I want
 viewing any record I receives warning messages, codes 2 and 512, saying
 that the '''relation addresses_plots do not exists'''.[[BR]][[BR]]

 Other association types are fine.[[BR]][[BR]]

 Thanks for any help.

-- 
Ticket URL: <https://trac.cakephp.org/ticket/5268#comment:2>
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