Closed pishguy closed 7 years ago
Can u share the value of channel.channels_type_id
@thetutlage yes sure, i get undefined
unfortunately
for more information:
AlachiqChannels:
and that model:
'use strict'
const Lucid = use('Lucid')
class AlachiqChannel extends Lucid {
static get table() {
return 'alachiqChannels'
}
channelsTypeId() {
return this.belongsTo('App/Model/ChannelsType')
}
}
module.exports = AlachiqChannel
ChannelsType:
and that model:
'use strict'
const Lucid = use('Lucid')
class ChannelsType extends Lucid {
static get table() {
return 'channelsType'
}
alachigChannels() {
return this.hasMany('App/Model/AlachiqChannel')
}
}
module.exports = ChannelsType
What is the value of channels_type_id
with in the database?
in alachiqChannels
table i have more row which all of them have 1
on channels_type_id
and they are referenced on id
on channelsType
and on channelsType
that have one row with 1
data
alachiqChannels:
channelTypes:
Full Stack error:
WARN adonis:lucid +5ms Trying to fetch relationship with channels_type_id as primaryKey, whose value is falsy
Error: Undefined binding(s) detected when compiling SELECT query: select * from `channelsType` where `id` = ? limit ?
at QueryCompiler_MySQL.toSQL (/Applications/XAMPP/xamppfiles/htdocs/alachiq/node_modules/knex/lib/query/compiler.js:78:13)
at QueryBuilder.toSQL (/Applications/XAMPP/xamppfiles/htdocs/alachiq/node_modules/knex/lib/query/builder.js:61:44)
at /Applications/XAMPP/xamppfiles/htdocs/alachiq/node_modules/knex/lib/runner.js:46:32
From previous event:
at Runner.run (/Applications/XAMPP/xamppfiles/htdocs/alachiq/node_modules/knex/lib/runner.js:41:33)
at QueryBuilder.Target.then (/Applications/XAMPP/xamppfiles/htdocs/alachiq/node_modules/knex/lib/interface.js:32:43)
at next (/Applications/XAMPP/xamppfiles/htdocs/alachiq/node_modules/co/index.js:100:51)
at onFulfilled (/Applications/XAMPP/xamppfiles/htdocs/alachiq/node_modules/co/index.js:69:7)
at /Applications/XAMPP/xamppfiles/htdocs/alachiq/node_modules/co/index.js:54:5
at co (/Applications/XAMPP/xamppfiles/htdocs/alachiq/node_modules/co/index.js:50:10)
at toPromise (/Applications/XAMPP/xamppfiles/htdocs/alachiq/node_modules/co/index.js:118:63)
at next (/Applications/XAMPP/xamppfiles/htdocs/alachiq/node_modules/co/index.js:99:29)
@thetutlage could you find whats problem? i can't find
It's because the field name in the table is channel_type_id
whereas Adonis default foreign key is channels_type_id
Redefine your relation as
channelsTypeId() {
return this.belongsTo('App/Model/ChannelsType', 'id', 'channel_type_id')
}
@thetutlage Thanks, but after that my relation array is empty and i dont have channelsType
values on result:
AlachiqChannel {
attributes:
{ id: 1,
channelName: 'خبر و خبرگزاریهای رسمی',
channelLink: 'cafemaku/sajjadmajjad',
channelDescription: 'کانالهای خبرگزاری رسمی کشور',
channelImageFileName: 'boldt.jpg',
channelAvatarFileName: '34.jpg',
channelState: 0,
channel_type_id: 1,
channelOwnerUserId: 0,
fileServerUrlId: 0,
created_at: 2016-09-01T15:04:12.000Z,
updated_at: 2016-09-01T15:04:12.000Z },
original:
{ id: 1,
channelName: 'خبر و خبرگزاریهای رسمی',
channelLink: 'cafemaku/sajjadmajjad',
channelDescription: 'کانالهای خبرگزاری رسمی کشور',
channelImageFileName: 'boldt.jpg',
channelAvatarFileName: '34.jpg',
channelState: 0,
channel_type_id: 1,
channelOwnerUserId: 0,
fileServerUrlId: 0,
created_at: 2016-09-01T15:04:12.000Z,
updated_at: 2016-09-01T15:04:12.000Z },
transaction: null,
relations: {},
frozen: false,
eagerLoad:
EagerLoad {
withRelations: [],
withNestedRelations: {},
relationsScope: {},
nestedRelationsScope: {} } }
@tux-world You need to do: const chanels = yield channel.channelsTypeId().fetch()
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
I cant make simple relation ship between two table
my AlachiqChannel model
and ChannelsType model
I get this error: