cpierce / microsoft-sql-pdo-for-cakephp-2.x

MIT License
10 stars 5 forks source link

hasOne and hasMany relationship Different Datasources #2

Open amb3rl4nn opened 8 years ago

amb3rl4nn commented 8 years ago

Goal is to be able to access SQL Server from a LAMP environment. The only issue is that when I do a Find on the EpiArticle, it does not pull the hasMany items from the same SQL Datasource. However the hasOne item does link up fine from the Mysql Datasource

Description of Relationships and the datasource

EpiArticles are stored in SQL Server EpiArticleField are stored in SQL Server EpiArticleMeta are stored in Mysql Server

EpiArticle hasMany EpiArticleField EpiArticle hasOne EpiArticleMeta

Code for these models/relationships

DB CONFIG:
default = Mysql Server
epi_server = SQL Server

class EpiArticle extends AppModel {
    public $useDbConfig = 'epi_server';
    public $useTable = 'tblPage';
    public $primaryKey = 'pkID';

    var $hasMany = [
        'EpiArticleField' => [
            'foreignKey' => 'fkPageID',
        ],
    ];

    var $hasOne = [
        'EpiArticleMeta' => [
            'foreignKey' => 'rbuid2'
        ],
    ];
}

class EpiArticleField extends AppModel {
    public $useDbConfig = 'epi_server';
    public $useTable = 'tblProperty';
    public $primaryKey = 'fkPageDefinitionID';

    public $belongsTo = [
        'EpiArticle' => [
            'foreignKey' => 'fkPageID',
        ],
        'EpiField' => [
            'foreignKey' => 'fkPageDefinitionID',
        ]
    ];
}

class EpiArticleMeta extends AppModel {
    var $belongsTo = [
        'EpiArticle' => [
            'foreignKey' => 'rbuid2',
        ],
    ];
}

RESULTS OF THE QUERY

array(
    (int) 0 => array(
        'EpiArticle' => array(
            'pkID' => '27386',
            'fkPageTypeID' => '49',
            'fkParentID' => '27310',
            'ArchivePageGUID' => '',
            'CreatorName' => 'webservice',
            'PageGUID' => '6BA38741-D64B-4F9C-A1DD-B53EC5182753',
            'VisibleInMenu' => '0',
            'Deleted' => '0',
            'PendingPublish' => '0',
            'ChildOrderRule' => '1',
            'PeerOrder' => '1300',
            'ExternalFolderID' => '27585',
            'PublishedVersion' => '',
            'fkMasterLanguageBranchID' => '1',
            'PagePath' => '.1.3.13.15.26166.27310.'
        ),
        'EpiArticleMeta' => array(
            'id' => '191504',
            'rbpubdate' => '2015-09-17 19:45:00',
            'rbpubid' => 'zod_nl_dcn_prd',
            'rbuid1' => 'zod_nl_dcn_prd-27386',
            'rbuid2' => '27386',
            'rbuid' => 'http://www.dailycommercialnews.com/Economic/News/2015/9/A-Bang-on-Prescription-for-What-Ails-Canada-But-1010224W/',
            'statictitle' => 'A Bang-on Prescription for What Ails Canada, But…',
            'rbimguris1' => '/PageFiles/27585/001_RBI-image-1010225.jpeg',
            'rbimguris2' => ''
        ),
        'EpiArticleField' => array()  <------------  MISSING THIS DATA
amb3rl4nn commented 8 years ago

added formatting for the code... sorry

amb3rl4nn commented 8 years ago

So I have no idea why this would be the case... but if I use XDebug and pause execution on Sybase::_execute(...) Line 779... Then play forward for the entire request. Everything comes back correctly with all data and fields. No issues. However if I do not pause the system. The related Model EpiArticleField always comes back blank.