This project is archived and is in readonly mode.

#5477 ✓committed
Brian Durand

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

Reported by Brian Durand | August 27th, 2010 @ 04:42 PM | in 3.0.2

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.

Comments and changes to this ticket

  • Jeremy Kemper

    Jeremy Kemper August 27th, 2010 @ 11:20 PM

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

    Jeremy Kemper October 15th, 2010 @ 11:02 PM

    • Milestone set to 3.0.2
  • Jason Langenauer

    Jason Langenauer November 16th, 2010 @ 10:48 AM

    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'

  • Aaron Patterson

    Aaron Patterson November 16th, 2010 @ 04:10 PM

    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...

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Referenced by

Pages