0

Model inheritance in Mojito

I'd like to make a base database-accessing model that other models can inherit from, to create a sort of ORM for Mojito.

Is there any way to use Y.extend or Y.Base.create in YUI to extend a Mojito model?  I see that Mojito models right now seem to simply act as regular JS objects, so I was thinking I could extend a base model's object with Y.Base, and then I would be able to use Y.Base.create to perform inheritance on that base model.

Would that be the best way to go to do inheritance with Mojito?  I haven't really seen too many examples of doing anything like that so far, so I was wondering what other people have done.

by
2 Replies
  • Clarence, that's the idea, but the support for that didn't land on master just yet. There are two things about this:

    1. as today, modules are instantiated by the framework automatically (in a very dummy way), which is about to change. In 0.5, they will be instantiated on demand when needed, and they can be a literal object (data proxy as today), or they can be a class (Y.Model) and the framework will instantiate them for you.

    2. there is nothing that prevent you from using your own models today. In your controller, u should be able to do `new Whatever()`, and `Whatever` could be defined under your autoload folder in your mojit or globally, it doesn't matter. What I'm trying to say here is that you don't need to use the "models" folder at all, and do it `a la YUI`.

    Best regards,
    Caridy

    QUOTE(Clarence Leung @ 27 Sep 2012 10:51 AM)
    I'd like to make a base database-accessing model that other models can inherit from, to create a sort of ORM for Mojito.

    Is there any way to use Y.extend or Y.Base.create in YUI to extend a Mojito model?  I see that Mojito models right now seem to simply act as regular JS objects, so I was thinking I could extend a base model's object with Y.Base, and then I would be able to use Y.Base.create to perform inheritance on that base model.

    Would that be the best way to go to do inheritance with Mojito?  I haven't really seen too many examples of doing anything like that so far, so I was wondering what other people have done.
    0
  • Thanks for all of the help, Caridy!

    I'm a little bit confused with what the difference between 0.5.0 and the current module implementation in Mojito is though.  Could you go into a little bit more detail about that?
    0

Recent Posts

in Yahoo! Mojito