I need to make a query that return all book_unit_questions of one Book.
So, i have the Book.Id.
I'm trying something like:
SELECT BO.id,
BUQ.description
FROM book_unit_question BUQ
JOIN book_unit BU
ON(BUQ.book_unit_id = BU.book_id)
INNER JOIN Books BO
ON(BU.book_id = 1)
But this way is returning id from other books, and i was expected some the id 1:
My migrations files:
class BookSchema extends Schema {
up () {
this.create('books', (table) => {
table.increments()
table.string('code').notNullable().unique()
table.string('description')
table.string('authors')
table.boolean('status').defaultTo(false)
table.integer('user_id').references('id').inTable('users')
table.timestamps()
})
}
class BookUnitSchema extends Schema {
up () {
this.create('book_unit', (table) => {
table.increments()
table.integer('book_id').references('id').inTable('books').notNullable()
table.integer('unit').notNullable()
table.integer('sequence').notNullable()
table.string('description')
table.integer('qt_question')
table.boolean('status').defaultTo(false)
table.integer('user_id').references('id').inTable('users')
table.timestamps()
table.unique(['unit', 'sequence', 'book_id'])
})
}
class BookUnitQuestionSchema extends Schema {
up () {
this.create('book_unit_question', (table) => {
table.increments()
table.integer('book_unit_id').references('id').inTable('book_unit')
table.string('question_form')
table.string('option_form')
table.string('type_answer')
table.string('description')
table.string('correct_answer_description')
table.integer('correct_answer_description_id')
table.text('image_sound')
table.boolean('status').defaultTo(false)
table.integer('user_id').references('id').inTable('users')
table.timestamps()
})
}