JasperGrimm / vue-crud

Vue CRUD item
MIT License
0 stars 0 forks source link

BaseModel class. CRUD operations #2

Open JasperGrimm opened 8 years ago

JasperGrimm commented 8 years ago

Setup connection and model-builder

import ModelBuilder from './modelBuilder'
const mb = new ModelBuilder('http://127.0.0.1:8080')
import models from './database'

Create City instance

let city = mb.get('city', {})
city.name = 'Jam'
city.id = 1
city.save()

or another way

let city = mb.get('city', {})
city.setData({
  id: 1,
  name: 'Jam'
})
city.save()

Create User instance and pass City reference into

let user = mb.get('user', {})
user.setData({
  id: id,
  name: name,
  city: city // reference to City (One-To-One)
})
user.save()