I am quite new to Yii (switching from CodeIgniter) and would like to know if I can add attributes to relations.
Example: I have a User and I have a list of Skills. Now I want to assign Skills to a User by using a relationship. To assign a skill to a User I will use an assignment-Table if I understood this correctly.
Now I want to add an Attribute to this relationship to express how well the User is in this Skill.
Example: I have a User who is assigned to the Skill "speaks English". To express how well he speaks English I would like to add an Attribute to this relationship.
a) Is this possible? How would I do that?
I will have to search for “All Users having Skill “speaks English” with a rating of min. 3 of 5 points”. How would I do this in Yii?
I read through the "through" feature but Im not sure if I got it right so I would like to clarify this:
[list=1]
[*]I have a User table, a Skill table and a User_Skill_Assignment table
[*]The User_Skill_Assignment table has the two foreign keys and a column "quality"
[*]In the User-class (=Model) I define a relationship "HAS_MANY" to the Skill-class (=Model).
[/list]
As far as I understood the "through" feature I can access another model (e.g. address) from the Skill-Model "through" the User-Skill-Address relationship. But where do I get the access to the attribute of the relationship between User and Skill?
You could give some short example? No need to write valid code though, just some idea.
Yes, you will need to create a model for the join table as well.
Check if this thread can help you out. Bad choice since it concludes not to use through. (This post will give you a brief explanation on your way back to the description in the guide.)
(As said, I still have to become familiar with the through mechanism)
Since you will need to create the third link table model anyway, you may consider the option to use that model as primary in your query and address two BELONGS_TO relations you’ve added to it.