I’ve got an object that looks a lot like a hash, and its valid
parameters are essentially arbitrary. I’m successfully storing these
objects, but now I need to be able to query them.
This is for my project Puppet, which manages many different classes
of objects, like files, services, packages, and users. Each of these
classes has its own set of valid parameters, and I’m adding new classes
and modifying existing classes all of the time, so I don’t want to
create a separate Rails table for each class. I also don’t want to
create a separate table for each class because I have a ‘host’ class
that functions as a collection of these objects, along with a bit of
other data (like its IP address); if I have a separate table for each
class, I’ll need a separate association for each one, also.
I’ve been storing them using an association, with the main info (class
and name) in one table, and the parameters in a separate table (e.g.,
the file’s owner, group, and mode) using associations.
However, I expect these queries won’t work well:
rails_parameters.name = ‘owner’ and rails_parameters.value = ‘root’ OR
rails_parameters.name = ‘owner’ and rails_parameters.value = ‘bin’
What is the best way to store these objects so that I can easily find
them? I’m assuming I can’t serialize the parameters and query against
them, since SQL has no clue about the serialized YAML.