Coder Social home page Coder Social logo

Comments (3)

toddself avatar toddself commented on June 19, 2024

Or is there another way this is supposed to work? Should I be providing some sort of extra template? The examples are pretty light when it comes to saving/fetching nested models.

from backbone-mongo.

kmalakoff avatar kmalakoff commented on June 19, 2024

Hello!

I've taken a look at your code and see that there are some conventions that need to be followed (some undocumented):

  1. Add callbacks are of the form "(err, result) ->" - that means "fetch(function(om2) {})" should be "fetch(function(err, om2) {})"

  2. The naming convention for models are:

    a) urls are underscored, pluralized: "/innermodel" should be "/inner_models"

    b) relationships are also underscored, but either pluralized or singularized depending on the relationship plurality: "innerModel" should be "inner_model"

  3. Because the embedded relationship is stored on the OuterModel, the relationship should be "belongsTo" instead of "hasOne".

Other things

  1. Instead of using a url on the InnerModel, you could add a property 'model_name: "InnerModel"' to it (with CoffeeScript in Node, model_name and url are optional).

  2. The function around a relationship is only necessary for breaking dependency cycles so "innerModel: function(){return [...]}" could be simplified to "inner_model: [...]"

  3. We typically don't use the fetch mechanic, but findOne:

  OuterModel.findOne om.id, (err, om3) ->
    assert.deepEqual(om3.get('inner_model').attributes, om.get('inner_model').attributes)

You can find a working version of your code here. Also, I will update the documentation to make the conventions more clear.

Just let me know if you have any more problems.

from backbone-mongo.

toddself avatar toddself commented on June 19, 2024

@kmalakoff omg thank you so much for going through this! I'm going to go over it and implement the changes :)

Hope you had an excellent holiday!

from backbone-mongo.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.