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

Model relationship for Composite Keys ? #404

Closed
siddiquipro opened this issue Nov 17, 2018 · 2 comments
Closed

Model relationship for Composite Keys ? #404

siddiquipro opened this issue Nov 17, 2018 · 2 comments
Assignees
Labels
Type: Question Needs clarification

Comments

@siddiquipro
Copy link
Contributor

Package version

4.1.0

Node.js and npm version

node - 8.11.1
npm - 6.4.1

Sample Code (to reproduce the issue)

image

All these 3 fields have their master tables. I need to have a relationship matching the two PK fields from other models. I am not able to get it. Any help? Is it even possible?

@RomainLanz
Copy link
Member

Hey @mohammadsiddiqui! 👋

Composite keys aren't supported for the moment by Lucid.
@benjamincanac was working on a PR to make it works so we will see how it goes.

#382

@benjamincanac
Copy link
Contributor

Hi @mohammadsiddiqui,

Why do you need a primary key matching two PKs?

You could just references them and add a unique constraint on both of those fields:

'use strict'

const Schema = use('Schema')

class AssessmentModuleSchema extends Schema {
  up () {
    this.create('assessment_modules', (table) => {
      table.increments()
      table.integer('assessmentid').unsigned().references('id').inTable('assessments').notNullable()
      table.integer('surveyid').unsigned().references('id').inTable('surveys').notNullable()
      table.integer('ratingid').unsigned().references('id').inTable('ratings')
      table.unique(['assessmentid', 'surveyid'])
      table.timestamps()
    })
  }

  down () {
    this.drop('assessment_modules')
  }
}

module.exports = AssessmentModuleSchema

@thetutlage thetutlage self-assigned this Nov 7, 2019
@thetutlage thetutlage added Status: Abandoned Dropped and not into consideration Type: Question Needs clarification labels Nov 7, 2019
@thetutlage thetutlage removed the Status: Abandoned Dropped and not into consideration label Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question Needs clarification
Projects
None yet
Development

No branches or pull requests

4 participants