-
Notifications
You must be signed in to change notification settings - Fork 22k
Closed
Labels
Description
Actual behavior
Given the models:
class Task < ApplicationRecord
enum status: %i[pending completed not_completed]
end
class Query < ApplicationRecord
enum status: %i[pending completed not_implemented]
end
They will generates the following warnings:
# Task
An enum element in Task uses the prefix 'not_'. This will cause a conflict with auto generated negative scopes.
Creating scope :not_completed. Overwriting existing method Task.not_completed.
# Query
An enum element in Query uses the prefix 'not_'. This will cause a conflict with auto generated negative scopes.
It will also generate the two scopes:
Query.not_implemented
Query.not_not_implemented
Expected behavior
- The warning
The warning added by #36380 can be quite enigmatic, if not useless, when there are no conflicts in the enumeration.
Does it mean we should ban not_
words from enum ?
I don't think so.
The method detect_negative_condition
used in active_record/enum.rb#L203 should check the whole enum collection to detect potential conflicts.
- The scopes
Could we generate an implemented
scope instead of a not_not_implemented
?
I will be happy to propose a pull request (or two) after receiving some opinions.
System configuration
Rails version: 6.0.2.2
Ruby version: 2.6.3
MatheusRich and nikosmichas