Reputation: 2039
I have two types of profiles in the application, and they are two different tables. For example, personal profiles are in the 'person' table and their IDs begin with 'p', and the business profiles are in the 'business' table and their IDs begin with 'b'.
I have a 'like' table that creates a relation between a post and a profile. However, the profile is a conditional relation; if profile_id begins with 'b', it should be with the Business model, and if not, it should be with the 'Person' model.
I have tried to put in an if statement in the relation() method of the model. However, at that stage, the properties are not initialized and I get an error. I have tried using afterFind() and afterConstruct() to add a relation to the model's metadata (using CActiveRecordMetaData::addRelation()). When I echo the type of the relationships in either afterFind or afterConstruct, they are all what they should be. However, for some reason, when I try to loop through some results and access the relation, they are all identified as businesses. When I call CActiveRecord::refresh() exactly after I add the relations, I get an error, saying that the limit of 100 nested function calls is reached.
How can I implement this conditional relationship?
Upvotes: 0
Views: 142