question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reference document doesn't populate data

See original GitHub issue
var color = ottoman.model('Color', {
  value : {
    type : "string"
  }
})

var Furniture = ottoman.model('Fur', { 
   type: { type: 'string' },
   color : { ref : 'Color' }
 }
)

var c = new color({ value : "777777" });

c.save(function(err, doc){
  if(!err) {

    var test = new Furniture({
      type : 'couch',
      color : c
    })

    test.save(function(err, doc){
      console.log(test);
    })
  }
})

Furniture.find({}, function(err, doc){
  console.log('doc', doc[0].color);
})

the first logging show the color console.log(test); as // { value : 77777 }

OttomanModel(`Fur`, loaded, key:Fur|6ace0a3e-9465-4c26-a699-6ba6a7b1a995, {
  _id: '6ace0a3e-9465-4c26-a699-6ba6a7b1a995',
  type: 'couch',
  color: OttomanModel(`Color`, loaded, key:Color|64f8ac67-a334-4cf6-aa59-67c16a2cf3e2, {
    _id: '64f8ac67-a334-4cf6-aa59-67c16a2cf3e2',
    value: '777777',
  }),
})

the second logging console.log('doc', doc[0].color); show the color object but no data show up

    _id: '2ccf7aee-9f3e-45d0-b6da-fa003ab405ab',
    type: 'couch',
    color: OttomanModel(`Color`, unloaded, key:Color|0d4b1f7b-e4d9-4ee2-bc31-67c208d23b89, {}),

I notice the first call the color model is loaded, but i don’t understand why it is not loaded when using find.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
brett19commented, Aug 18, 2016

Just to add to @moxious’s answer. You can actually implicit load more of the submodels through various tools. You can pass the ‘load’ option to .find to specify specific paths to load (ie: .find({}, {load: ['color']}). You can also pass the ‘depth’ option to load all models up to a certain depth.

P.S. @moxious, recursive loading is supported. A->B->A will make B’s reference to A point to the actual model instance it already loaded as part of that .load call.

Cheers, Brett

0reactions
richard-dev-mxcommented, Oct 21, 2016

Yes, I was thinking that with the load option, ottoman load the definitions of the models from some place, but i reviewed the code and I see my mistake.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Document property doesn't populate data in MS Word Online
Solved: Hello All, I have this requirement of generating a Word Document when an item in a list is created.
Read more >
Solve issues with EndNote references in a document
Open a blank Word document and insert a few references. If the problem persists even in your new document, your problem is more...
Read more >
EndNote: Updating a Word document to match changes from ...
When changes made to an EndNote™ library are not being reflected in your document, try to format the bibliography in the document.
Read more >
Cloud Firestore Data model - Firebase
A reference is a lightweight object that just points to a location in your database. You can create a reference whether or not...
Read more >
Repeating Data (Populating Multiple Like Fields) - Greg Maxey
On-line forms are Word documents that have "fill in the blanks. ... Bonus Tip: Use of the field name REF is optional in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found