Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Add hooks for new data types

#5047

I work on plugin, which allows use of PostgreSQL array type.
While modifying it to work under Rails 3, i found two places, where need for "monkey patching" was too big. Both places are about deciding what to insert into SQL depending on value type.

First place is ActiveRecord::Base#arel_attributes_values .
It would be perfect, if rows

  if value && ((self.class.serialized_attributes.has_key?(name) && (value.acts_like?(:date) || value.acts_like?(:time))) || value.is_a?(Hash) || value.is_a?(Array))
    value = value.to_yaml
  end

would be refactored into hookable method. I suggest, it could be method in the ActiveRecord::ConnectionAdapters::AbstractAdapter

  if value && self.class.serialized_attributes.has_key?(name)
    value = value.to_yaml
  else
    value = self.class.connection.arel_attribute_value(value, column)
  ends
  module ActiveRecord
    module ConnectionAdapters
      class AbstractAdapter
        def arel_attribute_value( value, column )
          if value && ((value.acts_like?(:date) || value.acts_like?(:time)) || value.is_a?(Hash) || value.is_a?(Array))
            value.to_yaml
          else
            value
          end
        end
      end
    end
  end

or simply in separated ActiveRecord::Base method, depended on column

Second is ActiveRecord::PredicateBuilder#build_from_hash
Could following lines be refactored in separate method:

  case value
  when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::Relation
    values = value.to_a
    attribute.in(values)
  when Range, Arel::Relation
    attribute.in(value)
  else
    attribute.eq(value)
  end

Reported by Sokolov Yura · July 5th, 2010 @ 01:55 PM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Sokolov Yura
  2. Sokolov Yura
    Sokolov Yura
    • Tag changed from activerecord datatypes to activerecord datatypes, patched

    July 7th, 2010 @ 09:17 AM

  3. Sokolov Yura
    Sokolov Yura
    • Tag changed from activerecord datatypes, patched to activerecord datatypes, patch

    July 7th, 2010 @ 09:18 AM

  4. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:36 PM

  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:36 PM