Closed skatkov closed 6 years ago
I double checked migration again and here is what I have:
add_column :products, :categories, :text, array:true, nil: false, default: []
But readme proposes to use :string
If we would look into this article: https://www.depesz.com/2010/03/02/charx-vs-varcharx-vs-varchar-vs-text/
To sum it all up:
char(n) – takes too much space when dealing with values shorter than n, and can lead to subtle errors because of adding trailing spaces, plus it is problematic to change the limit
varchar(n) – it's problematic to change the limit in live environment
varchar – just like text
text – for me a winner – over (n) data types because it lacks their problems, and over varchar – because it has distinct name
what if we will add additional param as a requirement:
class Product < ApplicationRecord
acts_as_taggable_array_on :categories, as: :<column_type>
end
And make sure that it's included? (raise an error, if it's not) @tmiyamon what do you think?
Thank you for your suggestion. I agree not to stick to specific type in this gem.
It's good to add required type option but I think auto detection is more useful such as using type info of columns_hash['tag'].type
.
@tmiyamon thanks for a tip. I managed to do a quick fix that should address this. I'd appreciate if you can review it
Sorry, to bother you. Are there any issues @tmiyamon ?
Great work! Thank you for your contribution!
I've ran into issues, my setup includes:
If have following model:
Migration is as recommended in README. But then I use Product.withoutany{tags} i ran into casting issue. Example:
Following documentation refers to two two possible types in PG ARRAY -- text and integer. https://www.postgresql.org/docs/9.6/static/arrays.html
Varchar is not listed as supported type. So I changed current implementation and it works for my case (i'm not sure if it work for older PG version though)