Skip to content

How to work models with relationships? #117

Closed
@geoidesic

Description

@geoidesic

I'm confused about how to work models and relationships.

So for example, I have a form, which stores a related model id as 'enquiry_type_id. However when I fetch data via jsonapi-vuex this key is missing from the attributes, instead I'm supposed to get it via getRelated`? (I think). But then how do I map that back to my vue-component's model?

So I have a component declared like this (pug syntax):

q-select(
                  label="Enquiry type"
                  :value="form.enquiry.enquiry_type_id"
                  @input="enquiryUpdater('enquiry_type_id', $event)"
)

enquiryUpdater looks like this:

enquiryUpdater(fieldName, ev) {
      this.$set(this.form.enquiry, fieldName, ev.value);
},

When I load the form I'm doing:

this.$set(this.form, "enquiry", this.$store.getters['enquiries/get']('enquiries/1'));

... but that value is failing to load because it's not present in the vuex store as an attribute, only as a relationship.

Probably I'm doing it all wrong but I can't think of a better way. You mentioned something about using getters and setters instead of a data model but I don't know how that would look or work. For example when I'm editing the form it has to write to a model for that q-select component, so what would my component's :value prop and @input function look like in order to integrate with jsonapi-vuex's relationships?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requestedstale

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions