{"action":"created","issue":{"url":"https://api.github.com/repos/cakephp/cakephp/issues/6539","labels_url":"https://api.github.com/repos/cakephp/cakephp/issues/6539/labels{/name}","comments_url":"https://api.github.com/repos/cakephp/cakephp/issues/6539/comments","events_url":"https://api.github.com/repos/cakephp/cakephp/issues/6539/events","html_url":"https://github.com/cakephp/cakephp/issues/6539","id":75311362,"number":6539,"title":"3.0.4 - Associations now can't call Table::table without erroring out","user":{"login":"patrickconroy","id":954577,"avatar_url":"https://avatars.githubusercontent.com/u/954577?v=3","gravatar_id":"","url":"https://api.github.com/users/patrickconroy","html_url":"https://github.com/patrickconroy","followers_url":"https://api.github.com/users/patrickconroy/followers","following_url":"https://api.github.com/users/patrickconroy/following{/other_user}","gists_url":"https://api.github.com/users/patrickconroy/gists{/gist_id}","starred_url":"https://api.github.com/users/patrickconroy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patrickconroy/subscriptions","organizations_url":"https://api.github.com/users/patrickconroy/orgs","repos_url":"https://api.github.com/users/patrickconroy/repos","events_url":"https://api.github.com/users/patrickconroy/events{/privacy}","received_events_url":"https://api.github.com/users/patrickconroy/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/cakephp/cakephp/labels/Defect","name":"Defect","color":"f7c6c7"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/cakephp/cakephp/milestones/40","html_url":"https://github.com/cakephp/cakephp/milestones/3.0.5","labels_url":"https://api.github.com/repos/cakephp/cakephp/milestones/40/labels","id":1101248,"number":40,"title":"3.0.5","description":"Bugfixes and optimizations for 3.0.x","creator":{"login":"markstory","id":24086,"avatar_url":"https://avatars.githubusercontent.com/u/24086?v=3","gravatar_id":"","url":"https://api.github.com/users/markstory","html_url":"https://github.com/markstory","followers_url":"https://api.github.com/users/markstory/followers","following_url":"https://api.github.com/users/markstory/following{/other_user}","gists_url":"https://api.github.com/users/markstory/gists{/gist_id}","starred_url":"https://api.github.com/users/markstory/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markstory/subscriptions","organizations_url":"https://api.github.com/users/markstory/orgs","repos_url":"https://api.github.com/users/markstory/repos","events_url":"https://api.github.com/users/markstory/events{/privacy}","received_events_url":"https://api.github.com/users/markstory/received_events","type":"User","site_admin":false},"open_issues":17,"closed_issues":20,"state":"open","created_at":"2015-05-08T01:49:40Z","updated_at":"2015-05-11T18:28:02Z","due_on":"2015-05-24T04:00:00Z","closed_at":null},"comments":1,"created_at":"2015-05-11T18:18:56Z","updated_at":"2015-05-11T18:37:24Z","closed_at":null,"body":"Hi guys. I have a master `Table` that my Tables extend. That class overrides Cake's `Table::table`, since my plugins can't associate with each other unless they have the full DB address.\r\n\r\n```\r\npublic function table($table = null)\r\n{\r\n\tif ($table === null) {\r\n\t\t$conn = ConnectionManager::config($this->defaultConnectionName());\r\n\t\t$table = parent::table();\r\n\t\tif (strpos($table, '.') !== false) {\r\n\t\t\treturn $table;\r\n\t\t}\r\n\t\treturn $conn['database'] . '.' . $table;\r\n\t}\r\n\treturn parent::table($table);\r\n}\r\n```\r\n\r\nTable1..\r\n```\r\n$this->addAssociations([\r\n\t'hasMany' => [\r\n\t\t'Vendor/Plugin.TableAlias2'\r\n\t]\r\n]);\r\n```\r\n\r\nThen..\r\n```\r\n$sections = $table1->find()->contain(['TableAlias2']);\r\n```\r\nErrors out with:\r\n``\"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'TableAlias2.database_name.foreign_key' in where clause\"``\r\n\r\n\r\n3.0.3 works without any problems. It looks like the change in `ExternalAssociationTrait` for foreignKeys did this. Changing it back to this works:\r\n```\r\npublic function foreignKey($key = null)\r\n{\r\n...\r\n            $this->_foreignKey = $this->_modelKey($this->source()->alias());\r\n...\r\n}\r\n```\r\nThe return from `MySuperTable::table` is always right. I'm not sure what part of the core is adding the funky table alias directly to the SQL. If a `Table` calls `Table::table`, I'd expect the SQL that queries use would use that table, and not try to reconstruct it at another point. Not sure what that change in the core is for so I don't know if I should try to debug as it stands or change that back..?\r\n\r\nThanks\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/cakephp/cakephp/issues/comments/101012193","html_url":"https://github.com/cakephp/cakephp/issues/6539#issuecomment-101012193","issue_url":"https://api.github.com/repos/cakephp/cakephp/issues/6539","id":101012193,"user":{"login":"markstory","id":24086,"avatar_url":"https://avatars.githubusercontent.com/u/24086?v=3","gravatar_id":"","url":"https://api.github.com/users/markstory","html_url":"https://github.com/markstory","followers_url":"https://api.github.com/users/markstory/followers","following_url":"https://api.github.com/users/markstory/following{/other_user}","gists_url":"https://api.github.com/users/markstory/gists{/gist_id}","starred_url":"https://api.github.com/users/markstory/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markstory/subscriptions","organizations_url":"https://api.github.com/users/markstory/orgs","repos_url":"https://api.github.com/users/markstory/repos","events_url":"https://api.github.com/users/markstory/events{/privacy}","received_events_url":"https://api.github.com/users/markstory/received_events","type":"User","site_admin":false},"created_at":"2015-05-11T18:37:24Z","updated_at":"2015-05-11T18:37:24Z","body":"This issue was likely introduced in #6344. Where the foreign key names are now generated from the table name instead of the alias name."}}