Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to map v-model to relationships? #247

Open
geoidesic opened this issue Aug 22, 2020 · 1 comment
Open

How to map v-model to relationships? #247

geoidesic opened this issue Aug 22, 2020 · 1 comment

Comments

@geoidesic
Copy link

geoidesic commented Aug 22, 2020

Let's say I have an entity enquiry that is related to another entity person. So now I have an enquiry edit form where I want to show a select option of people and show which person is currently selected as being associated with the enquiry.

How would one handle that from a v-model perspective? One can't map enquiry.attributes.person_id because that doesn't exist. To get the related person one would have to do this.$store.getters[person/related]({parent: enquiryEntity}).

I'm guessing one would have to create a getter / setter mapping like:

<template lang="pug">
div
    select(v-model="person_id")
        options(v-for="person in people" value="person.id") {{person.attributes.name}} 
</template>
<script>
computed: {
    person_id: {
        get() { return this.$store.getters[`person/related`]({parent: enquiryEntity})[0].id },
        set(val) {
             this.$store.commit('STORE_RELATED', { params: {relationship: 'person'}, [val] })
        }
    }
}

Is that even correct? Is there an easier way?

What's extra confusing is that in the case of a form for handling a new enquiry. JSONAPI is perfectly happy having person_id within attributes. This doesn't break the spec and will create the required association on the back-end.

However when retrieving that record via JSONAPI person_id will not be present in attributes.

@geoidesic geoidesic changed the title How to map vuex to relationships? How to map v-model to relationships? Aug 22, 2020
@CodingItWrong
Copy link
Contributor

FYI, this library will be unmaintained going forward.

If you need new features or fixes, I recommend forking the repo and making changes, or finding an alternate library that meets your needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants