#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:  wontfix =>

Comment:

 Hi core team.[[BR]]
 [[BR]]
 The solution presented by '''__ADNL__''' (and by other people) simply does
 not work well, but I think we need to solve this problem for good.[[BR]]
 [[BR]]
 The facts are:[[BR]]
 [[BR]]
 - There are two different PostgreSQL schemas, '''{{{schA}}}''' and
 '''{{{schB}}}''';[[BR]]
 - There are two different, but related, data tables, '''{{{schA.tabA}}}'''
 and '''{{{schB.tabB}}}''';[[BR]]
 - There are two different applications, '''{{{appA}}}''' and
 '''{{{appB}}}''':[[BR]]
 - '''{{{appA}}}''' has a model, '''{{{modA}}}''', wich uses
 '''{{{schA.tabA}}}''';[[BR]]
 - '''{{{appB}}}''' has a model, '''{{{modB}}}''', wich uses
 '''{{{schB.tabB}}}''';[[BR]]
 - The models above are '''hasAndBelongsToMany''' associated. The link
 table is in '''{{{schA}}}''', so there is a table named
 '''{{{schA.tabA_tabB}}}''';[[BR]]
 - The link model, '''{{{modA_modB}}}''', was explicitly created and uses
 the same '''useDbConfig''' of '''{{{modA}}}''', because it belongs to
 '''{{{appA}}}'''.[[BR]][[BR]]

 Important! The tests was done using scaffolding. CakePHP 1.2 RC3.[[BR]]
 [[BR]]
 I ran the core code to find out how stuff works; how CakePHP acts in these
 situations. I found out that if you are running the
 '''{{{appA}}}''':[[BR]]
 [[BR]]
 ^[a]^ Before you reads the '''{{{modA}}}''''s data, CakePHP will really
 connect to PostgreSQL using the '''{{{modB}}}''''s '''useDbConfig'''
 configuration, which is related, because it tests the match of the two
 models '''useDbConfig''' configurations.[[BR]]
 [[BR]]
 Bingo! An error message flashes at this moment.[[BR]]
 [[BR]]
 If you trying to run the '''{{{appB}}}''', keeping the logic above ^[a]^
 in mind, the problem stays worse.[[BR]]
 [[BR]]
 I'm not the only one that develops applications in these conditions.
 Someone else more in the planet must go through the same situation. So I
 put my head to work (and my hands)![[BR]]
 [[BR]]
 The solution is knowing the PostgreSQL schema's name of the  link table, I
 thought, in the case the '''useDbConfig''' of the two models didn't match.
 If this happens, I have to explicitly put the schema's name in the SQL
 code generated by the CakePHP.[[BR]]
 [[BR]]
 I wrote a new function that returns the PostgreSQL schema's name of the
 link model. I'm not sure if this function is in the correct file but it
 works fine.[[BR]]
 [[BR]]
 I also did some few modifications in some lines and voilĂ ![[BR]]
 [[BR]]
 The local tests ran fine. The solution seems very simple to me. Am I
 beeing too much optimistic?[[BR]]
 [[BR]]
 The '''{{{cake_1.2_rc3_diff.txt}}}''' that contains the changes I made
 follows attached. Please review the content.[[BR]]
 [[BR]]
 Thanks a lot.[[BR]]
 [[BR]]
 P.S. Sorry for my poor english.

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