Defining relationships with more than one column


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:


Ok ..... so found this post which answers most of my question (should of searched harder):

$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?



what you are looking for is scoped model/relationship

it is currently not supported