Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing urls to relational collections in backbone

I'm using Backbone relational and it's great. The problem I have run into is when I need the backend to provide the url for models to attach to.

This isn't such a problem when using one-to-one relationships because the model can hold onto the url as an attribute of itself.

The collection on the other hand creates a separate model within itself.

What is the best way to bind these together. Examples below

{
    "user": {
        "url": "http://example.com/api/user/1"
    },
    "permissions": {
        "url": "http://example.com/api/user/1/permissions"
    }
}

In the above example, I want user to be a model with the url provided, and the permissions a collection, with the url provided.

What I have tried is to get the collection working is the following:

{
    "permissions": {
        "url": "https://example.com/api/user/1/permissions"
        "data": []
    }
}

But I wasn't able to run a parse that extracts the variables out.

like image 829
lededje Avatar asked Nov 10 '22 15:11

lededje


1 Answers

If you have not set {parse: true} on your relation definition (documentation), then you should do so, and see if that fixes your problem. Otherwise, it would help if you provided more code.

like image 194
Michael.Lumley Avatar answered Nov 15 '22 00:11

Michael.Lumley