diff options
Diffstat (limited to 'activerecord/lib/active_record')
| -rw-r--r-- | activerecord/lib/active_record/associations.rb | 6 | ||||
| -rw-r--r-- | activerecord/lib/active_record/enum.rb | 7 |
2 files changed, 7 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 5a3b4f0c40..260ef71e64 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1438,7 +1438,7 @@ module ActiveRecord # when you access the associated object. # # Scope examples: - # belongs_to :user, -> { where(id: 2) } + # belongs_to :firm, -> { where(id: 2) } # belongs_to :user, -> { joins(:friends) } # belongs_to :level, ->(level) { where("game_level > ?", level.current) } # @@ -1516,9 +1516,9 @@ module ActiveRecord # belongs_to :attachable, polymorphic: true # belongs_to :project, readonly: true # belongs_to :post, counter_cache: true - # belongs_to :company, touch: true + # belongs_to :comment, touch: true # belongs_to :company, touch: :employees_last_updated_at - # belongs_to :company, required: true + # belongs_to :user, required: true def belongs_to(name, scope = nil, options = {}) reflection = Builder::BelongsTo.build(self, name, scope, options) Reflection.add_reflection self, name, reflection diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb index 442fb3fdc9..470e0b5d29 100644 --- a/activerecord/lib/active_record/enum.rb +++ b/activerecord/lib/active_record/enum.rb @@ -36,6 +36,7 @@ module ActiveRecord # needs: # # Conversation.where(status: [:active, :archived]) + # Conversation.where.not(status: :active) # # You can set the default value from the database declaration, like: # @@ -69,9 +70,8 @@ module ActiveRecord # Conversation.statuses[:active] # => 0 # Conversation.statuses["archived"] # => 1 # - # Use that class method when you need to know the ordinal value of an enum. For - # example, you can use that when manually building a SQL string inside a `where` - # condition: + # Use that class method when you need to know the ordinal value of an enum. + # For example, you can use that when manually building SQL strings: # # Conversation.where("status <> ?", Conversation.statuses[:archived]) # @@ -106,6 +106,7 @@ module ActiveRecord end def type_cast_from_database(value) + return if value.nil? mapping.key(value.to_i) end |
