Help with a weird model relation?

Hey guys,

I’ve got a really weird set of database tables that I’m trying to work into a model relation, but I’m not sure if Yii will be able to do it the way I need.

Here are my tables



-(various attributes)






Basically, a “rule” is an association between two classifications. The “behavior” attribute tells me if two classifications will stack together. It’s weird because it’s basically a many to many relationship with itself.

The problem is, I need a relation called “rules” on classification to get all the “classification_rule” rows that apply to the classification. In other words, “INNER JOIN classification_rule r ON r.classification_index_1 = c.index OR r.classification_index_2 = c.index”. It doesn’t matter if the classification is the first or second FK in the rules table. It’s almost as if I’m trying to make a two HAS_MANY relations to each of the FKs and and combine the two together with an “or”.

Is there any way to do this with a model relation? So far I haven’t had any luck.