Я очень новичок в feathersjs, я застрял в запросе к базе данных, который использует LEFT JOIN.Я прочитал sequelizejs, но я застрял.У меня есть 2 таблицы.
Таблица 1:
Table "public.ek_jabatan"
Column | Type | Modifiers
----------------+--------------------------+-----------------------------------------------------------------
id_jabatan | integer | not null default nextval('ek_jabatan_id_jabatan_seq'::regclass)
id_instansi | integer | not null
nama_jabatan | character varying(100) | not null
urutan_jabatan | integer | not null
createdAt | timestamp with time zone |
updatedAt | timestamp with time zone |
Indexes:
"ek_jabatan_pkey" PRIMARY KEY, btree (id_jabatan)
Таблица 2:
Table "public.ek_instansi"
Column | Type | Modifiers
---------------+--------------------------+-------------------------------------------------------------------
id_instansi | integer | not null default nextval('ek_instansi_id_instansi_seq'::regclass)
nama_instansi | character varying(100) | not null
lokasi | character varying(200) | not null
createdAt | timestamp with time zone |
updatedAt | timestamp with time zone |
Indexes:
"ek_instansi_pkey" PRIMARY KEY, btree (id_instansi)
В PHP этоне сложно сделать Query:
SELECT id_jabatan, a.id_instansi, nama_jabatan, urutan_jabatan, nama_instansi, lokasi
FROM ek_jabatan a
LEFT JOIN ek_instansi b
ON b.id_instansi = a.id_instansi
Как сделать Query подобным образом на FeatherJS ???
я попробовал,
users.model.js
const Sequelize = require('sequelize');
const DataTypes = Sequelize.DataTypes;
module.exports = function (app) {
const sequelizeClient = app.get('sequelizeClient');
const users = sequelizeClient.define('users', {
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true
},
password: {
type: DataTypes.STRING,
allowNull: false
},
statusId: {
type: Sequelize.INTEGER,
field: 'status_id'
}
}, {
hooks: {
beforeCount(options) {
options.raw = true;
}
}
});
// eslint-disable-next-line no-unused-vars
users.associate = function(models){
users.hasOne(models.userStatus, {
as: 'status',
foreignKey: 'id'
});
};
return users;
};
user_status.model.js
const Sequelize = require('sequelize');
const DataTypes = Sequelize.DataTypes;
module.exports = function (app) {
const sequelizeClient = app.get('sequelizeClient');
const userStatus = sequelizeClient.define('user_status', {
name: {
type: DataTypes.STRING,
allowNull: true
}
}, {
hooks: {
beforeCount(options) {
options.raw = true;
}
}
});
userStatus.associate = function (models) {
};
return userStatus;
};
users.hooks.js
before: {
all: [],
find: [
authenticate('jwt'),
context => {
const sequelize = context.params.sequelize || {};
sequelize.raw = true;
sequelize.include = [
{
model: context.app.services['userStatus'].Model,
as: 'status'
}
];
return context;
},
],
get: [ authenticate('jwt') ],
create: [ hashPassword() ],
update: [ hashPassword(), authenticate('jwt') ],
patch: [ hashPassword(), authenticate('jwt') ],
remove: [ authenticate('jwt') ]
},
Когда начинается npm, я получаю сообщение об ошибке.бросить новую ошибку (this.name + '.' + Utils.lowercaseFirst (Type.toString ()) + ', вызванную с чем-то, что не является подклассом Sequelize.Model');