Skip to content
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

Tighten up some options.Model/Sequelize/getModel related code. #267

Merged

Conversation

AndrewJDR
Copy link
Contributor

Firstly, some background:
feathers-sequelize allows for overriding of its getModel method
in order to let users implement their own model provider schemes;

Overriding getModel() in this way allows for a different Model to be programatically
provided any time getModel() is called.
This can allow for multi-tenancy setups where different customer models/databases
are used depending upon different criteria, such as what hostname they're connecting to,
where they are connecting from, or whatever the programmer desires.

Currently, the feathers-sequelize Service class requires that a single Model be provided
in the options passed to its constructor. The problem is, when using a getModel() override
as described above, a single Model is probably not known at the time that the feathers-sequelize
Service constructor is called.

Therefore, a Model probably shouldn't be required at construction time.

This changeset makes providing a Model optional, adds an alternative option attribute called 'Sequelize'
for providing the Sequelize class (which is currently used to derive the default Ops), and
adds some warning messages inside of the Model getter to dissaude usage of it altogether other than
for coverage tests, since using this getter doesn't allow for proper getModel() overriding.

Firstly, some background:
feathers-sequelize allows for overriding of its getModel method
in order to let users implement their own model provider schemes;

Overriding getModel() in this way allows for a different Model to be programatically
provided any time getModel() is called.
This can allow for multi-tenancy setups where different customer models/databases
are used depending upon different criteria, such as what hostname they're connecting to,
where they are connecting from, or whatever the programmer desires.

Currently, the feathers-sequelize Service class requires that a single Model be provided
in the options passed to its constructor. The problem is, when using a getModel() override
as described above, a single Model is probably not known at the time that the feathers-sequelize
Service constructor is called.

Therefore, a Model probably shouldn't be required at construction time.

This changeset makes providing a Model optional, adds an alternative option attribute called 'Sequelize'
for providing the Sequelize class (which is currently used to derive the default Ops), and
adds some warning messages inside of the Model getter to dissaude usage of it altogether other than
for coverage tests, since using this getter doesn't allow for proper getModel() overriding.
@AndrewJDR
Copy link
Contributor Author

Side note, I'm actually wondering whether it's a good idea to have the .Model way of accessing the model in the first place?

It creates a problem for extended service classes that override getModel() to do more interesting things with providing different models under different situations based on parameters, so maybe it's better if a "parameter-less" version of getModel (i.e. the .Model getter) just didn't exist at all...

@daffl
Copy link
Member

daffl commented Jan 25, 2019

Thanks. I did remove the getModel but many applications still relied on it. It probably should be removed in the next major version. Also removed the console.warn since we got bit before by logging things that you can't turn off.

@daffl daffl merged commit b7175c2 into feathersjs-ecosystem:master Jan 25, 2019
@AndrewJDR
Copy link
Contributor Author

Thanks. I did remove the getModel but many applications still relied on it. It probably should be removed in the next major version. Also removed the console.warn since we got bit before by logging things that you can't turn off.

@daffl just to clarify, you mean that .Model will be removed?

@daffl
Copy link
Member

daffl commented Jan 26, 2019

Yes. But it will have to be another breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants