Skip to content
This repository has been archived by the owner on Oct 15, 2018. It is now read-only.

Describe how to use associations with existing tables #109

Open
KSDaemon opened this issue Feb 8, 2016 · 1 comment
Open

Describe how to use associations with existing tables #109

KSDaemon opened this issue Feb 8, 2016 · 1 comment

Comments

@KSDaemon
Copy link

KSDaemon commented Feb 8, 2016

Hi! In one-to-one association at the bottom there is a section about using existing tables. But it only covers how to specify a table name and table columns for simple attributes. But how can i specify a foreign key name for association?
I mean something like this:

var User = Waterline.Collection.extend({

  identity: 'user',
  connection: 'local-postgresql',
  tableName: 'pb_user'

  attributes: {
    id: {
      type: 'integer',
      primaryKey: true
    },
    firstName: {
      type: 'string',
      columnName: 'pb_owner_first'
    },
    lastName: {
      type: 'string',
      columnName: 'pb_owner_last'
    },

    // Add a reference to Pet
    pet: {
      model: 'pet'
      columnName: : 'pb_pet_id'     // << foreign key existing column name
    }
  }
});

So, from db point, there is a pb_pet_id column, which is foreign key, but from js/waterline view — we'll get a pet object, that is associated with user.

@dv336699
Copy link

dv336699 commented Mar 2, 2016

this repo is for issues regard waterline-docs, I think you should get an answer if you post your question (which is not an issue) on stackoverflow

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

No branches or pull requests

2 participants