-
Notifications
You must be signed in to change notification settings - Fork 39
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
Дубровин Алексей #16
base: master
Are you sure you want to change the base?
Дубровин Алексей #16
Conversation
🍏 Пройден линтинг и базовые тесты |
🍏 Пройден линтинг и базовые тесты |
@@ -21,6 +21,15 @@ const Cart = sequelize.import('models/cart'); | |||
const User = sequelize.import('models/user'); | |||
|
|||
// Ваши relations между моделями :) | |||
Cart.belongsTo(User); | |||
Cart.belongsToMany(Souvenir, { through: 'cart_souvenirs' }); | |||
Review.belongsTo(Souvenir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Souvenir.hasMany(Review)
достаточно
Cart.belongsToMany(Souvenir, { through: 'cart_souvenirs' }); | ||
Review.belongsTo(Souvenir); | ||
Review.belongsTo(User); | ||
User.hasOne(Cart); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Уже есть Cart.belongsTo(User)
Review.belongsTo(Souvenir); | ||
Review.belongsTo(User); | ||
User.hasOne(Cart); | ||
User.hasMany(Review); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Также с Review.belongsTo(User)
} | ||
}, { | ||
timestamps: true | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нет необходимости явным образом определять что либо в этой модели.
id
, createdAt
, updatedAt
проставляются неявно Sequelize'ом.
userId также появится засчёт связи Cart.belongsTo(User)
.
@@ -1,5 +1,18 @@ | |||
'use strict'; | |||
|
|||
module.exports = (sequelize, DataTypes) => { | |||
// Ваша модель страны | |||
return sequelize.define('country', { | |||
id: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Аналогично про id
type: DataTypes.INTEGER, | ||
allowNull: true | ||
} | ||
}, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Всё также, много лишних явных объявлений
@@ -1,5 +1,18 @@ | |||
'use strict'; | |||
|
|||
module.exports = (sequelize, DataTypes) => { | |||
// Ваша модель тэга | |||
return sequelize.define('tag', { | |||
id: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Аналогично
@@ -1,5 +1,18 @@ | |||
'use strict'; | |||
|
|||
module.exports = (sequelize, DataTypes) => { | |||
// Ваша модель юзера | |||
return sequelize.define('user', { | |||
id: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тоже
// подстрока substring. Поиск должен быть регистронезависимым. | ||
return this.Souvenir.findAll({ | ||
where: { | ||
name: { [Sequelize.Op.contains]: substring } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ilike
или iRegexp
для регистронезависимого поиска
const ratings = await this.Review.findAll({ where: { souvenirId } }).then(r => r.rating); | ||
souvenir.rating = ratings.reduce((a, b) => a + b, 0) / ratings.length; | ||
|
||
await souvenir.save(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Оберни в транзакцию
🍪 |
🍏 Пройден линтинг и базовые тесты |
No description provided.