Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Enhance CManyManyRelation (make tableName available) #508

cebe opened this Issue · 2 comments

1 participant


If you need to manually build a query that relies on a relation defined in an ActiveRecord it is hard to get the name of the many-many-table for MANY_MANY relation.

I can already get the relation by calling $model->getActiveRelation('relationName') which gives me an instance of CManyManyRelation.
But there I only have the foreignKey property which I would have to parse with the same regex as it is done in CActiveFinder.php line 561.

It would be nice if I had a property of CManyManyRelation that gives me the table.
I started an implementation of that by moving the 7 lines after 561 to a method called getRelationTable() in CManyManyRelation. But there are many problems with that:

  1. I do not have the activerecord object this relation belongs to, so in case of Exception, I can not show AR class name anymore
  2. If I want to return the tableSchema object instead of table name only, I would need the schema, which also is not available there.

Giving the $model and $schema as parameters of the getter does not seem to be a good solution to me.
So things to change for that to work are much more than I thought in the beginning.
I think a CActiveRelation should have information about which activerecord it belongs to, what do you thing @qiangxue @samdark?


That might not have become clear: If the relation knows its activerecord model or even just the class name of it, implementation would be very easy.


this has been resolved by #878.

@cebe cebe closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.