Coder Social home page Coder Social logo

bookshelf-factory's People

Contributors

bhoriuchi avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

jdevries

bookshelf-factory's Issues

Example does not work

create database b_fac;
use b_fac;
create table posts (id int(11) auto_increment , name varchar(100), primary key(id));
create table tags (id int(11) auto_increment , slug varchar(100), primary key(id));
create table posts_tags(id int(11) auto_increment, post_id int(11), tag_id int(11), primary key(id), foreign key (post_id) references posts(id), foreign key (tag_id) references tags(id));
insert into posts (name) values ('eins');
var config = {
    "client": "mysql",
    "connection": {
        "host": "127.0.0.1",
        "user": "root",
        "password": "",
        "database": "b_fac",
        "charset": "utf8"
    }
};

// require the package and pass the db connection config
var factory = require('bookshelf-factory')(config);
var type = factory.schemer.constants.type;

// define a schema in schemer format
// in this example survivor.id has the views extended property that defines
// views that property belongs to. survivor.groups also has the extended
// property belongsToMany and specifies the model to use for the relationship
var schema = {
    posts: {
        id: {type: type.string},
        name: {type: type.string, size: 200},
        tags: {belongsToMany: 'tags', junction: 'posts_tags', foreignKey: 'post_id', otherKey: 'tag_id'},
    },
    tags: {
        id: {type: type.string},
        slug: {type: type.string, size: 100}
    },
    posts_tags: {
        id: {type: type.string},
        post_id: {type: type.string},
        tag_id: {type: type.string}
    }
};

// call the create function to create all the models
var models = factory.create(schema);

// forge the model and get all of its resources
models.posts.forge().getResources().then(function (results) {

    // pretty print the results to the console
    console.log(JSON.stringify(results, null, ' '));
});

I am getting

Unhandled rejection Error: ER_BAD_FIELD_ERROR: Unknown column 'tags.null' in 'on clause'

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.