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
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 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 August 28th, 2010 @ 08:02 AM
- State changed from open to committed
-
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:in
attributes_for' arel (2.0.2) lib/arel/table.rb:112:inmap' arel (2.0.2) lib/arel/table.rb:112:in
attributes_for' arel (2.0.2) lib/arel/table.rb:92:incolumns' arel (2.0.2) lib/arel/table.rb:100:in
[]' composite_primary_keys (3.0.0.b2) lib/composite_primary_keys/associations.rb:104:inassociation_join' activerecord (3.0.2) lib/active_record/relation/query_methods.rb:242:in
build_joins' activerecord (3.0.2) lib/active_record/relation/query_methods.rb:237:ineach' activerecord (3.0.2) lib/active_record/relation/query_methods.rb:237:in
build_joins' activerecord (3.0.2) lib/active_record/relation/query_methods.rb:177:inbuild_arel' activerecord (3.0.2) lib/active_record/relation/query_methods.rb:150:in
arel' activerecord (3.0.2) lib/active_record/relation.rb:64:into_a' activerecord (3.0.2) lib/active_record/relation/finder_methods.rb:189:in
find_with_associations' activerecord (3.0.2) lib/active_record/relation.rb:64:into_a' activerecord (3.0.2) lib/active_record/relation/finder_methods.rb:143:in
all' activerecord (3.0.2) lib/active_record/relation/finder_methods.rb:103:infind'
-
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>
People watching this ticket
Attachments
Referenced by
- 4270 Arel 0.3.2 broke non-standard column types https://rails.lighthouseapp.com/projects/8994/tickets/5477
- 5194 ActiveRecord Beta 4 does not understand most postgres data types Can you verify whether this is still an issue after the f...