Phil Pirozhkov
Phil Pirozhkov
@rubocop/style-guide-editors @koic WDYT?
Thanks for reporting! ```ruby (...2).exclude_end? # => true (..2).exclude_end? # => false (2...).exclude_end? # => true (2..).exclude_end? # => false ``` Rails makes no difference between `7.days.ago..` and `7.days.ago...`, and...
You're right! I've completely missed that there is no difference between an inclusive and exclusive endless ranges, TIL. Thanks for the interesting reference.
There are two more things that recently hit me: 3. We suggest defining the class on the top level: ```ruby class MigrationProduct < ActiveRecord::Base self.table_name = :products end class ModifyDefaultStatusForProducts...
4. Migration models are loaded as needed in development, while loaded all at once in production with `eager_load`. (this needs to be confirmed with the Rails code, if the migrator...
Another approach is to use: ```ruby def change MigrationFoo.reset_column_information MigrationFoo.find_each { |foo| foo.update!(category: 'primary') } end ``` See https://stackoverflow.com/a/9728033/202914 for explanation. Otherwise, an error is raised: ``` unknown attribute 'category'...
`reset_column_information` is what [Rails suggests using](https://github.com/rails/rails/blob/7600f6af1d4a1b8747dbd181f0e061d1f22d67f4/activerecord/lib/active_record/migration.rb#L442): > Sometimes you'll want to add a column in a migration and populate it immediately after. In that case, you'll need to make a...
One case when it's not possible to properly use migration model in migration when you use it to schedule an Active Job job: ```ruby class MigrationUser < ActiveRecord::Base self.table_name =...
I find the [original reasoning](https://github.com/rails/rails/issues/31209) confusing: > Expected behavior > NOT(A AND B) = NOT(A) OR NOT(B) To me, both `where.not(a: 1, b: 2)` and `where.not(a: 1).where.not(b: 2)` should be...
I side with @andyw8 and would recommend not using `where.not` with multiple attributes or chained. The few real-world usages of `where.not` with multiple attributes I could find in `real-world-rspec` repos:...