Skip to main content
added 21 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

There are a couple of options available, and you need to choose which one is suitable for your problem.

  1. Has And Belongs To Many association

This has been covered by Cba Bhusal@Cba Bhusal's answer. Downside The downside of this approach is that it will require extra query to DB each time you want to check status of a features. It's not always suitable.

  1. Embeed feature field if User model as bitmask.

Check this railscast for more information how it works.

The downside is that there is limit of how many features you can have this way and you are not allowed to change order or remove the features.

  1. Use separate field in user model for each feature

This is you approach. It's fine only if you have few features and do not plan to add more, otherwise choose something else.

  1. Add single text field to user model and serialize features to i.e. JSON

This gives you pretty much best extensibility with almost zero performance cost.

The downside is querying users by features - database won't understand serialized text field. If you need to do this there is a chance that your database supports data type you are serializing to, i.e. Postgres works fine with JSON or Array data types and Rails can take advantage of it.

There are couple of options available, you need to choose which one is suitable for your problem.

  1. Has And Belongs To Many association

This has been covered by Cba Bhusal answer. Downside of this approach is that it will require extra query to DB each time you want to check status of a features. It's not always suitable

  1. Embeed feature field if User model as bitmask.

Check this railscast for more information how it works.

The downside is that there is limit of how many features you can have this way and you are not allowed to change order or remove the features.

  1. Use separate field in user model for each feature

This is you approach. It's fine only if you have few features and do not plan to add more, otherwise choose something else.

  1. Add single text field to user model and serialize features to i.e. JSON

This gives you pretty much best extensibility with almost zero performance cost.

The downside is querying users by features - database won't understand serialized text field. If you need to do this there is a chance that your database supports data type you are serializing to, i.e. Postgres works fine with JSON or Array data types and Rails can take advantage of it.

There are a couple of options available and you need to choose which one is suitable for your problem.

  1. Has And Belongs To Many association

This has been covered by @Cba Bhusal's answer. The downside of this approach is that it will require extra query to DB each time you want to check status of a features. It's not always suitable.

  1. Embeed feature field if User model as bitmask.

Check this railscast for more information how it works.

The downside is that there is limit of how many features you can have this way and you are not allowed to change order or remove the features.

  1. Use separate field in user model for each feature

This is you approach. It's fine only if you have few features and do not plan to add more, otherwise choose something else.

  1. Add single text field to user model and serialize features to i.e. JSON

This gives you pretty much best extensibility with almost zero performance cost.

The downside is querying users by features - database won't understand serialized text field. If you need to do this there is a chance that your database supports data type you are serializing to, i.e. Postgres works fine with JSON or Array data types and Rails can take advantage of it.

Source Link
rui
  • 406
  • 2
  • 3

There are couple of options available, you need to choose which one is suitable for your problem.

  1. Has And Belongs To Many association

This has been covered by Cba Bhusal answer. Downside of this approach is that it will require extra query to DB each time you want to check status of a features. It's not always suitable

  1. Embeed feature field if User model as bitmask.

Check this railscast for more information how it works.

The downside is that there is limit of how many features you can have this way and you are not allowed to change order or remove the features.

  1. Use separate field in user model for each feature

This is you approach. It's fine only if you have few features and do not plan to add more, otherwise choose something else.

  1. Add single text field to user model and serialize features to i.e. JSON

This gives you pretty much best extensibility with almost zero performance cost.

The downside is querying users by features - database won't understand serialized text field. If you need to do this there is a chance that your database supports data type you are serializing to, i.e. Postgres works fine with JSON or Array data types and Rails can take advantage of it.