Skip to content

Trying to change the Rest url at runtime for a .$newCollection #9

@jackp55

Description

@jackp55

HI Vasilio!

It's me again!

Having a hard time trying to figure out how to change a .$newCollection of models's url at runtime.

We have scenarios where we have a model, and you can have several different Rest URLs to get a collection of these models.. depending on scenario.

  1. I can't seem to get the baseUrl(#)s from my model definition at runtime with .$newCollection, I can only get a 'baseUrl'.
  2. I CAN seem to get different 'baseUr(#) if I use a .$new, but I need a .$newCollection
  3. The fetch ({url:urlValue}) doesn't seem to work for .$newCollection either

So:

// Lets define some models first, with different Rest urls
// =============================

modelize.defineModel('post', {
  baseUrl: '/blog/postsdefault',
  baseUrl1: '/blog/posts111',
  baseUrl2: '/blog/posts222',
  baseUrl3: '/blog/posts333'',
...
  })
});

// Fetch collection
// ================
// Create empty collection
var posts = Post.$newCollection();

// Then fetch with different paths
// these are just different scenarios of course

var baseUrl = posts.baseUrl  // works
var baseUrl1 = posts.baseUrl1  // undefined
var baseUrl2 = posts.baseUrl2  // undefined
var baseUrl3 = posts.baseUrl3  // undefined

posts.fetch({ url: baseUrl1 }); 
posts.fetch({ url: baseUrl2 }); 
posts.fetch({ url: baseUrl3 }); 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions