Giter Site home page Giter Site logo

vuex-orm-examples's Introduction

Vuex ORM Examples

The example application to demonstrate the use case of the Vuex ORM. It's a simple ToDo application which can add assignee to each todo. You can see how Vuex ORM connects those two models โ€“ Todo and Assignee โ€“ and how to create, edit and delete them.

Vuex ORM Example

Running The Example

Clone this repository and then run following commands.

$ npm install
$ npm run serve

# Or with yarn.

$ yarn install
$ yarn serve

Then you can access http://localhost:3000 to play with the app!

Contribution

If you have any idea to make this example application easier to understand to people who are new to the Vuex ORM, please open an issue, or pull request ๐ŸŽ‰

vuex-orm-examples's People

Contributors

cuebit avatar kiaking avatar treby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vuex-orm-examples's Issues

retrieving many-to-many relationships

Hi,

I am receiving the following error when trying to retrieve a man-to-many relationship...
"TypeError: Cannot read property 'data' of undefined"

My models are setup like so:

export default class User extends Model {
    static get entity () {
        return 'users'
    }
    static fields () {
        return {
            id: this.attr(null),
            name: this.attr(''),
            email: this.attr(''),
            roles: this.belongsToMany(Role, RoleUser, 'user_id', 'role_id')
        }
    }
}

export default class Role extends Model {
    static get entity () {
        return 'roles'
    }
    static fields () {
        return {
            id: this.attr(null),
            name: this.attr(''),
            permissions: this.belongsToMany(Permission, RolePermission, 'role_id', 'permission_id')
        }
    }
}

export default class Permission extends Model {
    static get entity () {
        return 'permissions'
    }
    static fields () {
        return {
            id: this.attr(null),
            name: this.attr(''),
        }
    }
}

export default class RoleUser extends Model {
    static get entity () {
        return 'role_users'
    }
    static primaryKey () {
        return ['role_id', 'user_id']
    }
    static fields () {
        return {
            role_id: this.attr(null),
            user_id: this.attr(null)
        }
    }
}

export default class RolePermission extends Model {
    static get entity () {
        return 'role_permissions'
    }
    static primaryKey () {
        return ['role_id', 'permission_id'];
    }
    static fields () {
        return {
            role_id: this.attr(null),
            permission_id: this.attr(''),
        }
    }
}

Inside my component's created() method i am calling to create the user data:

const data = {
                    id: 1,
                    name: 'John Doe',
                    email: '[email protected]',
                    roles: [
                        {
                            id: 1,
                            name: 'admin',
                            permissions: [
                                {
                                    id: 1,
                                    name: 'create user'
                                }
                            ]
                        },
                    ]
                };

                this.$store.dispatch('entities/users/create', { data });

If i then make a computed property in the same component:

users() {
    return this.$store.getters['entities/users/all']();
}

Then this works OK!!

But if i try to get the role relation:

users() {
    return this.$store.getters['entities/users/query']()
                    .with('roles')
                    .get();
}

It gives the error above!!!

how to include vuex-orm-localforage?

I am wondering how to include vuex-orm-localforage into this demo app.

I tried to include the following code from the readme

import VuexORMLocalForage from 'vuex-orm-localforage'

const database = new VuexORM.Database()

VuexORM.use(VuexORMLocalForage, {
  database
})

into src/store/index.js so it now looks like:

import Vue from 'vue'
import Vuex from 'vuex'
import VuexORM from '@vuex-orm/core'
import VuexORMLocalForage from 'vuex-orm-localforage'
import database from '@/database'

Vue.use(Vuex)

VuexORM.use(VuexORMLocalForage, {
  database
})

const store = new Vuex.Store({
  namespaced: true,
  plugins: [VuexORM.install(database)]
})

export default store

But I am not able to enter any user name nor todo. Maybe this approach was to naiv, but how can it be accomplished?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.