evan / has_many_polymorphs

An ActiveRecord plugin for self-referential and double-sided polymorphic associations.
http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/
Academic Free License v3.0
201 stars 57 forks source link

has_many_polymorphs fails with Postgres DB and columns with capitalized letters #12

Open pr0zac opened 14 years ago

pr0zac commented 14 years ago

I've been creating a rails project using has_many_polymorphs to create associations between models. Some of these models store data in columns directly related to keys in incoming/outgoing plists. This has resulted in some of the columns having capitalized names. Unfortunately, postgres automatically lowercases all characters in passed column names unless they are correctly double quoted. In its current form, has_many_polymorphs does not correctly handle this case. The error looks similar to this:

CollectionsMember Load (0.0ms) PGError: ERROR: column devices.udid does not exist LINE 1: ...S t0_r2, collections_members.updated_at AS t0_r5, devices.Udid...

I have managed to force things to work correctly by adding quotes around column names in base.rb, function instantiate_with_polymorphic_checks, and in class_methods.rb, function build_table_aliases, though this is likely just a stop gap, as I haven't tested its effects on any other databases, and not fit for actual integration.

This issue likely effects a lot more people than just me, as this seems like a pretty common use case, and can hopefully be addressed quickly.