Model hasone multi column work on 1.34 but not work on 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

where I am going wrong?



61.1k
edited Jul '16

this is how I use mine:

//model initialize...

$this->hasOne(
    "brand",
    "Shop\Models\Brands",
    "id",
    [
    "alias" =>  "brandRecord"
    ]
);

//after that i use it:

$rec->getBrandRecord()->getName();


182

If use single relation column. it's work but I use multi relation column. It's not work on Phalcon 2.0.13

this is how I use mine:

```php

//model initialize...

$this->hasOne( "brand", "Shop\Models\Brands", "id", [ "alias" => "brandRecord" ] );

//after that i use it:

$rec->getBrandRecord()->getName();

```



61.1k

ahaa, ok. i am at work atm so i dont have time to compile 2.0 cuz i am on 2.1, hopefully someone else can test it out faster

Create issue on github.



61.1k
edited Jul '16

ok, in 3.0 branch this works for me.

class del1 extends \Phalcon\Mvc\Model
{

    public function initialize()
    {
        $this->setSource("delete_1");

        $this->hasOne(
            ["type", "type_2"],
            __NAMESPACE__ . "\del2",
            ["type", "type_2"],
            [
                "alias" =>  "kokoRec"
            ]
        );

    }
}
class del2 extends \Phalcon\Mvc\Model
{

    public function initialize()
    {
        $this->setSource("delete_2");
    }
}


//DB

CREATE TABLE `delete_1` (
  `id` int(11) NOT NULL,
  `type` int(11) NOT NULL,
  `type_2` int(11) NOT NULL,
  `name` varchar(222) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `delete_1` (`id`, `type`, `type_2`, `name`) VALUES
(1, 1, 1, 'text for type 1'),
(2, 1, 1, 'text for type 2');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `delete_1`
--
ALTER TABLE `delete_1`
  ADD PRIMARY KEY (`id`);


CREATE TABLE `delete_2` (
  `id` int(11) NOT NULL,
  `type` int(11) NOT NULL,
  `type_2` int(11) NOT NULL,
  `koko` varchar(111) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


INSERT INTO `delete_2` (`id`, `type`, `type_2`, `koko`) VALUES
(1, 1, 1, 'this should be type 1 link'),
(2, 2, 2, 'this should be type 2 link');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `delete_2`
--
ALTER TABLE `delete_2`
  ADD PRIMARY KEY (`id`);


 //and the dump is :


 array (size=4)
  'id' => int 1
  'type' => int 1
  'type_2' => int 1
  'koko' => string 'this should be type 1 link' (length=26)

I guess it was fixed in 2.1.x