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

Retational tables based on object types

Is it possible to have a "hasMany" relationship depended on a column value?

IE

users (has-many) id | data | ...

$this->hasMany("id", "files", "objectId", array(
    'alias' => 'userFiles'));
        // is there some way to add some type of if type ="users" 

customers (has-many) id | data | ...

$this->hasMany("id", "files", "objectId", array(
    'alias' => 'customerFiles'));
    // is there some way to add some type of if type ="customer" 

files (belongs-to) id | type | objectId | data

$this->belongsTo(/* ??? */);


34.6k
Accepted
answer

HA great timing it just released.