Hi
I am trying to implement user properties and make them flexible and easy to modify.
I have 3 tables and corresponding ActiveRecords:
Property (the one with property definitions)
(name
, caption
, constrained
, multiple
)
For example:
aboutMe About me 0 0
country Country 1 0
accessGroup Access Groups 1 1
PropertyValue (available property values)
( propertyId
, value
, caption
)
For example:
3 1 USA
3 2 Barbados
4 1 First group
4 2 Second group
And the mapping table UserProperty:
( userId
, propertyId
, value
)
1 1 About me value
1 3 3
1 4 ["1","3"]
I want to pass an array of UserProperty models to the view along with User model and render it.
If properties is already in the table it is easy to do with relations:
In User class:
/**
* @return \yii\db\ActiveQuery
*/
public function getUserProperty()
{
return $this->hasMany(UserProperty::className(), ['userId' => 'id'])
->indexBy('id')
->inverseOf('user');
}
But is there a way to create a list of empty UserProperties if it is not set yet?
In other words i want UserProperty model to be created for every Property available.