I have 3 Models I am working with Client, Feature and FeatureMaster
'FeatureMaster' holds the default values of features for all 'Clients'.
'Feature' is the clients specific value of the feature.
I need to be able to list and edit all features for a client.
Editing the value of a feature in this list will update the 'Feature' if it already exists or create a new 'Feature' if using the 'FeatureMaster's default.
Certainly,
A feature is simply a name / value pair with some info about how it can be used.
An example feature could be "Upload Images" which could allow clients to upload an image.
Feature's have default values in FeatureMaster and if it needs to be different it's stored in the Feature table.
You could do it in sql by first loading all features for a client in an array, and then all feature_masters that have no corresponding feature (by using where COUNT(..) = 0 sql function).
Or use a Ruby solution. First load all feature_masters into a hash. The keys of the hash should be the id's and the values the feature_masters. Then load all features for a specified client. Next iterate over these features and set hash[feature.feature_master_id] = feature. Now you have a hash table with the client's features or default values if the client doesn't have those features.
Bookmarks