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.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

Arel won't let ActiveRecord query against tables that have columns it doesn't know how to handle

#5477

There is an incompatibility between arel and activerecord in which arel will not let you query against a table that contains a column with a SQL type that arel doesn't know how to handle.

I ran across this when trying to map a table that contains a PostGIS geometry column in Rails 3. If I do MyModel.first, it works because ActiveRecord knows how to handle the geometry column. However, if I call MyModel.find(1) it blows up because Arel doesn't know how to handle the column type when it maps out the table columns into attributes.

My fix is to introduce a generic Undefined attribute type in arel instead of raising an error. That way arel will only blow up if you try to query on a column it doesn't know about.

Reported by Brian Durand · August 27th, 2010 @ 04:42 PM

State: committed
Milestone: 3.0.2
Assigned to: Aaron Patterson Aaron Patterson
Importance: Low

Activity

  1. Jeremy Kemper
    Jeremy Kemper
    • Milestone cleared.
    • State changed from new to open
    • Assigned user set to Aaron Patterson
    • Importance changed from to Low

    August 27th, 2010 @ 11:20 PM

  2. Aaron Patterson
  3. Jeremy Kemper
  4. Jason Langenauer
    Jason Langenauer

    This bug appears to have regressed in Rails 3.0.2 - I'm seeing the same error raised from a PostgreSQL BIGINT column. Stack trace below:

    arel (2.0.2) lib/arel/attributes.rb:16:in for' arel (2.0.2) lib/arel/table.rb:113:inattributes_for' arel (2.0.2) lib/arel/table.rb:112:in map' arel (2.0.2) lib/arel/table.rb:112:inattributes_for' arel (2.0.2) lib/arel/table.rb:92:in columns' arel (2.0.2) lib/arel/table.rb:100:in[]' composite_primary_keys (3.0.0.b2) lib/composite_primary_keys/associations.rb:104:in association_join' activerecord (3.0.2) lib/active_record/relation/query_methods.rb:242:inbuild_joins' activerecord (3.0.2) lib/active_record/relation/query_methods.rb:237:in each' activerecord (3.0.2) lib/active_record/relation/query_methods.rb:237:inbuild_joins' activerecord (3.0.2) lib/active_record/relation/query_methods.rb:177:in build_arel' activerecord (3.0.2) lib/active_record/relation/query_methods.rb:150:inarel' activerecord (3.0.2) lib/active_record/relation.rb:64:in to_a' activerecord (3.0.2) lib/active_record/relation/finder_methods.rb:189:infind_with_associations' activerecord (3.0.2) lib/active_record/relation.rb:64:in to_a' activerecord (3.0.2) lib/active_record/relation/finder_methods.rb:143:inall' activerecord (3.0.2) lib/active_record/relation/finder_methods.rb:103:in find'

    November 16th, 2010 @ 10:48 AM

  5. Aaron Patterson
    Aaron Patterson

    Sorry about that. Looks like I didn't add a test, so this got lost. :-(

    I've added a test and we'll have a bugfix release of arel shortly.

    https://github.com/rails/arel/commit/f0139a16c263ba62e7e45d462a4fff...

    November 16th, 2010 @ 04:10 PM