SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,095
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)

    ActiveRecord relationship

    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.

    Hope that makes some kind of sense..


    Cheers,
    Last edited by markbrown4; Jul 18, 2008 at 18:23.

  2. #2
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post your table structures and/or some examples of what a feature is?

  3. #3
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,095
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    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.

  4. #4
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •