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.

InstanceDefaults and relationships for populated data

See original GitHub issue

I would like to make use of the Relationships for populated data as described in the documentation. Unfortunately, I’ve been having trouble getting it to work. Nor do I really understand how it could work as shown in the documentation.

Actual behavior

While the model name for my service is recognized (gets set to null), no data is populated. After going through the code, I wasn’t sure how it would work as it is written in the documentation. My id fields are called “user_id” instead of “userId” as in the example, though I couldn’t find a reason for that not to work. The services own id fields are simply “id”. From what I understood of the feathers-vuex sourcecode (I’m somewhat new to javascript) seemed to indicate that the foreign id field should get the default value of the model. That got me further, but then the following code in model.js (lines 182-189) have me confused on their function.

const model = new Model(item)
const id = model[idField]_
_const storedModel = store.state[model.constructor.namespace].keyedById[id]_

…results in id being undefined and not doing anything on the last line.

By changing that line to:

const storedModel = store.state[model.constructor.namespace].keyedById**[item]**

…I actually managed to get it to populate the id field with the service data. I’m not too sure that is a real solution though. I’m not sure what a reference to another model looks like… So I was hoping someone could shed some light on what I’m doing wrong.

Expected behavior

I would like to add a property that refers to another model as shown in the documentation on relationships for populated data. So I’d like to keep the original “user_id” property and add a “user” property that references the actual user model. Currently a get an object in user_id that is a full representation of a user. Not sure how to check if it’s a reference or a copy…

Steps to reproduce

I think it’s hard to make a reproduction, with so many parts working together. But all the services work seperately, it’s just that I can’t get the populated data to work.

service('api/todos', {
      instanceDefaults: {
        user_id: 'User',
      }
    }),

Is my current service declaration. The ‘api/’ is an unfortunate choice made when this project was started. Could that have anything to do with it? It seems to be irrelevant on every other functionality I’ve seen.

System configuration

The services are KnexJs connecting to a PostgreSQL db.

Module versions (especially the part that’s not working): Feathers-vuex 1.4.8 Feathersjs 3.1.7 Feathers-knex: 3.3.0 Knex: 0.15.0

NodeJS version: v8.11.3

Operating System: Windows 10

Browser Version: Chrome: 68.0.3440.106

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
marshallswaincommented, Dec 15, 2018

It’s much more efficient to populate on the server than it is to make all of the requests from the client. I’d recommend looking into the feathers-plus/cli and looking into the GraphQL features. They allow the client to specify to the server which records to populate with each query. It’s the future, and it’s here. 😃

0reactions
marshallswaincommented, Jan 15, 2019

Another way to populate data is now available. See docs for instanceDefaults, here: https://feathers-plus.github.io/v1/feathers-vuex/model-classes.html#instanceDefaults-Function-pre-release

It’s intended to do one-off requests to get related data for a single record.

Read more comments on GitHub >

github_iconTop Results From Across the Web

InstanceDefaults and relationships for populated data #155
I would like to make use of the Relationships for populated data as described in the documentation. Unfortunately, I've been having trouble ...
Read more >
Common Patterns | FeathersVuex
In Feathers-Vuex 1.7, these could be specified in the instanceDefaults . As of 2.0, they are specified directly on each ... Relationships for...
Read more >
Common Patterns - FeathersVuex
Relationships for Populated Data. A common task with almost any API is properly handling relationships between endpoints. Imagine an API where you have ......
Read more >
Populating an attributed relationship class table (intermediate ...
Open the relationship class table to view the updated relationships and to input or edit data in the attribute fields. You must save...
Read more >
Remove | Sails.js 官方文档 - imfly
Used to remove records from the join table that is automatically generated during a many-to-many association. Unlike .add(), it only accepts the primary...
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