rubocop-rails
rubocop-rails copied to clipboard
Rails/CreateTableWithTimestamps shouldn't warn when id: false is used
In migrations you can create a join table like so:
create_table :games, :genres, id: false do |t|
t.integer :game_id
t.integer :genre_id
end
But Rails/CreateTableWithTimestamps will warn about this code because the table is being created without timestamps. Join tables shouldn't have timestamps, so this is a false positive.
https://guides.rubyonrails.org/association_basics.html#creating-join-tables-for-has-and-belongs-to-many-associations
I think it's still useful to have timestamps on a join table, even if just for troubleshooting.
I disagree with @andyw8, because it's seems useless for habtm tables. It useful for more complex join tables. Simple join/habtm tables easily can increase time of response and overflood your db with unusable two magic time fields (think about that join record will be touch updated with updated_at when associated records will also update)
My opinion is to have only id's fields and when you really need timestamps - add them(during my 15y Rails career never had to use timestamps in simple habtm's)
Therefore I totally agree with @connorshea that this is false positive
Thank you Koichi!