Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model hasone/hasmany multi relation column work on 1.34 but not work on 2.0.13 #12035

Closed
CodeBanBan opened this issue Jul 27, 2016 · 3 comments
Closed
Assignees
Labels
need script to reproduce Script is required to reproduce the issue
Milestone

Comments

@CodeBanBan
Copy link

Current I use PHP 5.5 and Phalcon 1.34
need upgrade to PHP 5.6 and Phalcon 2.0.13


I have two models: PackageModel and PackageDetialModel

In PackageModel inside intialilize():

public function initialize() {
   $this->hasOne(['id', 'referenceTypeID'],
            PackageDetialModel::class,
            ['referenceID', 'referenceTypeID'],
            [
                'alias' => 'detail',
        );
}

when I get detail by

$list = PackageModel::find();
foreach ($list as $item) {
    $detail = $item->detail;
 }

on Phalcon 1.34 will return result
but on Phalcon 2.0.13 will return FALSE

@andresgutierrez andresgutierrez added the need script to reproduce Script is required to reproduce the issue label Jul 29, 2016
@sergeyklay sergeyklay self-assigned this Aug 1, 2016
@sergeyklay
Copy link
Contributor

@CodeBanBan Could you please provide table schema?

@CodeBanBan
Copy link
Author

CodeBanBan commented Aug 2, 2016

@sergeyklay thankyou

CREATE TABLE `package` (
  `reference_type_id` int(11) NOT NULL,
  `reference_id` int(10) unsigned NOT NULL,
  `title` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `created` int(10) unsigned NOT NULL,
  `updated` int(10) unsigned NOT NULL,
  `deleted` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`reference_type_id`,`reference_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO `package` (`reference_type_id`, `reference_id`, `title`, `created`, `updated`, `deleted`) VALUES
(1, 1,  'Private Package #1',   0,  0,  NULL),
(1, 2,  'Private Package #2',   0,  0,  NULL),
(2, 1,  'Public Package #1',    0,  0,  NULL);

CREATE TABLE `package_detail` (
  `reference_type_id` int(11) NOT NULL,
  `reference_id` int(10) unsigned NOT NULL,
  `type` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `value` text COLLATE utf8_unicode_ci NOT NULL,
  `created` int(10) unsigned NOT NULL,
  `updated` int(10) unsigned NOT NULL,
  `deleted` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`reference_type_id`,`reference_id`,`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO `package_detail` (`reference_type_id`, `reference_id`, `type`, `value`, `created`, `updated`, `deleted`) VALUES
(1, 1,  'detail',   'private package #1 - detail',  0,  0,  NULL),
(1, 1,  'option',   'private package #1 - option',  0,  0,  NULL),
(1, 2,  'detail',   'private package #2 - detail',  0,  0,  NULL),
(1, 2,  'option',   'private package #2 - option',  0,  0,  NULL),
(2, 1,  'coupon',   'public package #1 - coupon',   0,  0,  NULL),
(2, 1,  'detail',   'public package #1 - detail',   0,  0,  NULL),
(2, 1,  'option',   'public package #1 - option',   0,  0,  NULL);

@sergeyklay
Copy link
Contributor

Fixed in the 3.0.x branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need script to reproduce Script is required to reproduce the issue
Projects
None yet
Development

No branches or pull requests

3 participants