Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Restore default ability to globally set defaults for all models#66

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
kinsi55 wants to merge3 commits intoKSDaemon:master
base:master
Choose a base branch
Loading
fromkinsi55:master

Conversation

@kinsi55
Copy link

Allows to define global values to set for all models.

Description, Motivation and Context

I found myself where I have a certain column for all of my Models, repeadetly defining them is not really DRY thus I've tried to copy original functionality of Waterlin whereattributes defined insails.config.models are merged into the Models themselves (Except I'm merging the seperate keysails.config.sequelize.modelDefaults to avoid breaking changes).

What is the current behavior?

Theres no way to globally define default values for models

What is the new behavior?

Any key not defined in the Model that exists insails.config.sequelize.modelDefaults will get merged into it

What kind of change does this PR introduce?

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • I have added tests to cover my changes.
  • Overall test coverage is not decreased.
  • All new and existing tests passed.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.0%) to 79.907% when pulling04b3ff3 on kinsi55:master into9123b26 on KSDaemon:master.

@KSDaemon
Copy link
Owner

Hi@kinsi55 ! First of all, thanks for contributing!
I think it's a good feature!

Well, there are a few little bits to make this PR better:

  • Will be great, if you extend README with an example of modelDefaults as object.
  • There is no test for this new feature. I'm trying to cover all code with tests, and especially new ones. So we can be sure it will work as expected in the future.

@kinsi55
Copy link
Author

I was just trying to get this out quickly as I've wanted to use it myself. I'll try to add a test for it / extend the readme when I get around to it. If you happen to be interested in doing it you're ofc free to do it :P Dont know when I'd get around to it.

@KSDaemon
Copy link
Owner

I don't think it's gonna take long! ;)
Just a simple example with a few common options + 1 test, that checks that options are propagated to models ;)

@kinsi55
Copy link
Author

kinsi55 commentedAug 11, 2019
edited
Loading

I've a question - when using this hook / Sequelize doesnt it essentially prevent you from using the normal ORM / Waterline alongside? If so I'd just switch it to using sails.config.models instead of the custom key as that makes things more streamlined.

@KSDaemon
Copy link
Owner

Well, it's possible to use both: sequelize and waterline models at the same time.
I don't think it's a good idea to store sequelize configuration in sails.config.models as it is supposed to be used in waterline. Also, keys and options may differ, so let's save it separately.

@prusswan
Copy link

Found out that Sequelize can do this using the beforeDefine global hook (seesequelize/sequelize#4383)

Example:

   options: {      dialect: 'postgres',      host   : 'localhost',      port   : 5432,      logging: console.log, // or specify sails log level to use ('info', 'warn', 'verbose', etc)      hooks: {        beforeDefine: (attributes) => {          attributes = Object.assign(attributes, {            createdAt: { type: Sequelize.BIGINT, field: 'created_at' },            updatedAt: { type: Sequelize.BIGINT, field: 'updated_at' },          });          sails.log("beforeDefine", attributes);        }      },   }

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@kinsi55@coveralls@KSDaemon@prusswan

[8]ページ先頭

©2009-2025 Movatter.jp