We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

select from one model to one model by two fields

Hi, i will know if it's possible. I have Concatcs and Tipos class

     class Contacts extends Phalcon\Mvc\Model
     /*
     * @Primary
     * @Identity
     * @Column(type="integer", nullable=false)
     */
    public $id;
    public $type; 
    public $origen_id; 
    public $name; 

    public function initialize()
    {
        $user = $this->getDI()->getSession()->get('auth');
        $this->setSource('contacts');
        $this->belongsTo('type', 'Tipos', 'id');
        $this->belongsTo('origen_id', 'Tipos', 'id',['alias'=>'Origenes']);
    }  
class Tipos extends Phalcon\Mvc\Model{
    public $id;
    public $name;
    public $tipo_id;
    public function initialize()

    {
        $this->belongsTo('tipo_id', // which column
                 'Tipos', // referenced table
                 'id', // referenced table column
                 ['alias' => 'parent']);        
    }
}

two questions, ¿could i use Contacts->Tipos->name and Contacts->Origenes->name? ¿how to construct phalcon\tag select()?

Thanks.



7.4k

I solve it using three classes, Contacts, Tipos and Origenes, wich source is Tipos. ¿Is possible to do this relation without third class?



7.4k

Thanks Yes, it's work when i'm using alias to solve Contacts->Tipos->name and Contacts->Origenes->name, but not work in Tag\select becouse isn't a model (I think).