Because the definitions of certain objects in our models are growing
out of control, we're looking into the possibility of simply defining
some of our objects in XML, rather than using many models and having
to use complicated join queries that make our application quite heavy.
Basically, we're defining machines that have many, many attributes.
Not all machines use the same attribute definitions and some of them
are very different from other machines, but we want to define them all
in one "root" model called "machine". Our application builds "bigger
machines" using these smaller machines, so we want the application to
know specifically what it can and cannot do. In the basic MVC
structure, this would mean we would have to have many models and they
all would be linked one way or another. Putting them together gets you
all you need to know about the machine.
What we would like to do however is define our machines like this:
<button id="1">Power switch</button>
<button id="2">Reset switch</button>
This is, of course, a simplified example.
We would like to have a model with simply an id (which is the
machine's id within the application) and a field to put this xml into.
So far so good, I of course know how to do this.
However, this would, as far as I can tell, limit the great
possibilities that Rails models have to offer. I would not be able to
@machine = Machine.find(params[:id])
num_buttons = @machine.buttons.count
I would have to do something with @machine.xml instead and I'm not
very sure what.
So, my question is this: how can I put all that XML-data into a MySQL-
table and get information from it the smart way?