Skip to content

Submodel reference after .save() #6

@dfliess

Description

@dfliess

Hi!

I'm not sure if I'm doing something wrong, or if it's a language, backbone or backbone-schema issue, I have something like this:

var computoSF;
var project;

function test2() {
    var factory = new Backbone.Schema.Factory();

    CYA.Models.DatosProyecto = factory.create({
        "id": "/schemas/datosProyecto",
        "type": "object",
        "properties": {
            "name": {
                "title": "Nombre",
                "description": "Nombre y Apellido",
                "type": "string",
                "required": true,
                "minLength": 4
            }
        }
    });


    CYA.Models.ComputoSF = factory.create({
        "id": "/schemas/computo",
        "type": "object",
        "title": "Computo Steel Framing",
        "properties": {
            "id": {
                "title": "id",
                "type": "number"
            },
            "description": {
                "title": "Descripcion",
                "type": "string"
            },
            "project": {
                "$ref": "/schemas/datosProyecto#",
                "required":true
            }
        }
    });

    computoSF = new CYA.Models.ComputoSF({
        "description": "default text",
        "project": {
            "name": "Diego A. Fliess"
        }
    });

    computoSF.url = 'test';

    computoSF.save(); //server response is the same object with an id. { "description": "default text", project": { "name": "Diego A. Fliess" }, "id": 3 }

    project = computoSF.get('project');
    project.set('name','Juan Gomez');

    computoSF.set('description', 'Some text');

    console.log('description inside function: ' + computoSF.get('description'));  //Juan Gomez
    console.log('project inside function: ' + project.get('name'));  //Juan Gomez
    console.log('computoSF inside function: ' + computoSF.get('project').get('name')); //Juan Gomez
}
> test2()
description inside function: Some text test2.js:58
project inside function: Juan Gomez test2.js:59
computoSF inside function: Juan Gomez test2.js:60
undefined
XHR finished loading: "http://localhost:3000/test". jquery.min.js:2

> computoSF.get('description') 
"default text"
> computoSF.get('project').get('name'); 
"Diego A. Fliess"
> project.get('name');  
"Juan Gomez"

My question is how to make the "parent" model computoSF have it's child (and subchilds) .get('project') updated, as if they where a reference.

Hope you can help me, and sorry if It's not a backbone-schema specific issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions