// In my app I render a table of Portal.Documents (I fetch the
model instances using findAll)
// This call will include documents of all types in one list, e.g.
word and excel
// Here is where it gets tricky: As a user I want to now edit one
document, e.g. if I wanted to edit the individual metadata (in a
single page //application scenario). As it is a Word document I want
to "cast" the generic Portal.Document instance as a
Portal.WordDocument, in order //to make the subsequent code cleaner
(more object oriented perhaps).
//At the moment I do this:
var wordDoc = new Portal.WordDocument(doc.serialize());
//However One of the main problems with this is that there are now
two model instances representating the same object ( same row
//in the DB table essentially). So when I update the attributes of
one, the canJS magic does not automatically update the other.
Am I going about this the right way? I'm trying to avoid having
a Portal.Document model class that has code that needs to handle all
types of documents, e.g.
//I want to avoid this
Am I going about this the right way?
To summarise, I want a generic findAll for documents, but would
like to separate unique behaviour for different types into subclasses.
But I also want the live binding to continue working, so that when the
subclass is updated, so is the instance of the "generic" document.
Thanks for the suggestions. I like the idea of overwriting the models
method, but I've decided to go down the safe route to avoid
unforeseen issues with doing anything too fancy, I've decided to
scrap the sub classes and just attach a "config" object to
each model instance based on their type.
Leave a comment on bryon.chan's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic