This project is archived and is in readonly mode.

#3515 ✓stale
ronin-77928 (at lighthouseapp)

has_many associations forced to have integer ids

Reported by ronin-77928 (at lighthouseapp) | November 27th, 2009 @ 05:02 PM

In my app I am using uuids (strings) as primary keys for my tables. It seems that Rails 2.3.5 now forces you to use integer ids in has_many and habtm associations.

define_method("#{reflection.name.to_s.singularize}_ids=") do |new_value|
  ids = (new_value || []).reject { |nid| nid.blank? }.map(&:to_i)
  send("#{reflection.name}=", reflection.klass.find(ids).index_by(&:id).values_at(*ids))
end

If I try to assign ids and not whole objects, the integer conversion destroys the id strings and thus no association object can be found. Without the conversion everything works fine (again).

I added a patch with a small fix.

Comments and changes to this ticket

  • Rohit Arondekar

    Rohit Arondekar October 6th, 2010 @ 06:30 AM

    • State changed from “new” to “stale”
    • Importance changed from “” to “”

    Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.

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

Pages