Defining relationships with more than one column

Hello,

I am trying to setup a relationship that requires 2 columns to be referenced in my relationship definition.

I have a comments table that is used by many different models throughout the system and within the Comment table I reference masterobjectid - defining the ID of the model, and also masterobjectclass - defining the model that 'owns' this comment.

Ideally i would like to say the following:

$this->hasMany(array('id', 'ClassName'), 'Comment', array('masterobjectid', 'masterobjectclass'));

The first array element is the id of $this model and is mapped to 'masterobjectid' of the comments table. Then also the ClassName (which I would like to be able to give the value in the hasMany call if thats possible, and not reference a table column) is mapped to 'masterobjectclass'.

Is this possible, or if not is there a way to approach this sort of relation using the Phalcon methods?

Read in the docs 'You could also use arrays to define multiple fields in the relationship.' but unclear how to go about this: http://docs.phalconphp.com/en/latest/reference/models.html#defining-relationships

Thanks

Ok ..... so found this post which answers most of my question (should of searched harder): http://forum.phalconphp.com/discussion/2707/does-hasmany-support-more-than-one-column-

$this->hasMany(array("id", "type"), "RobotsParts", array("robotsid", "robotstype"));

Is it possible to set type in the first array to a value instead of using a table column?

Cheers



1.5k

what you are looking for is scoped model/relationship

it is currently not supported