phalcon-devtools icon indicating copy to clipboard operation
phalcon-devtools copied to clipboard

Foreign key

Open iforp opened this issue 13 years ago • 3 comments

Phalcon DevTools v0.9.1

phalcon all-models --fk --relations

generates models like this

<?php
class Articles extends \Phalcon\Mvc\Model 
{
    public $id;

    // ...

    public function initialize()
    {
        $this->belongsTo("id", "Objects", "id");
        $this->addForeignKey("id", "Objects", "id");
        $this->addForeignKey("owner_id", "Objects", "id");
    }
}

But method \Phalcon\Mvc\Model::addForeignKey doesn't exist. Is it deprecated?

If so, how should I set foreign keys?

iforp avatar Feb 20 '13 16:02 iforp

It seems the generator is wrong, it must be:

<?php

class Articles extends \Phalcon\Mvc\Model 
{
    public $id;

    // ...

    public function initialize()
    {        
        $this->belongsTo("owner_id", "Objects", "id", array(
            'foreignKey' => true
        ));        
    }

}

ghost avatar Feb 20 '13 18:02 ghost

Thank you

iforp avatar Feb 21 '13 12:02 iforp

I updated a builder to support the new syntax and posted a pull request https://github.com/phalcon/phalcon-devtools/pull/123

MatejBalantic avatar Oct 16 '13 12:10 MatejBalantic