Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Enhance CManyManyRelation (make tableName available) #508

Closed
cebe opened this Issue Mar 15, 2012 · 2 comments

Comments

1 participant
Owner

cebe commented Mar 15, 2012

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?

Owner

cebe commented Mar 15, 2012

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.

Owner

cebe commented Aug 2, 2012

this has been resolved by #878.

@cebe cebe closed this Aug 2, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment