Is there a name for this pattern:

The basic principle is to store key:value data for an object in a
relational database.

The extra attributes table looks like this:

table attributes
object_klass:string
object_id:int
name:string
value:text

key:value data related to some other model.

Then the object definition would look something like this.

class Car
attr_accessor :props

def initialize
#=> get all schemaless attributes for this object
@props= Attribute.for_object(self)
end
end

There would also be a separate ‘cars’ table to store the essential data
regarding the Car model. The additional attributes are extra things that
might be different from instance to instance.

I’m sure variations of this are commonly used, I was just wandering if
there was an official “design pattern” name for it. Again, this is
referring to storing the data in a relational database.

Why not using an ORM which solves this for you?

Sequel [1] or ActiveRecord [2] are two popular examples in ruby land. If
they don’t offer the solution you expect out of the box, you can still
tweak the model classes to play as you wish.

[1]
http://sequel.jeremyevans.net/rdoc/files/doc/association_basics_rdoc.html

[2] http://guides.rubyonrails.org/association_basics.html

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs