-
Notifications
You must be signed in to change notification settings - Fork 39
Дубровин Алексей #16
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
base: master
Are you sure you want to change the base?
Дубровин Алексей #16
Conversation
|
🍏 Пройден линтинг и базовые тесты |
|
🍏 Пройден линтинг и базовые тесты |
| // Ваши 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).
| 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.
Всё также, много лишних явных объявлений
| 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.
Аналогично
| 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 для регистронезависимого поиска
| 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.