Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #2917 (closed enhancement: wontfix)

Opened 4 years ago

Last modified 3 years ago

[PATCH] Add collection_singular_ids method to habtm relationships

Reported by: François Beausoleil <francois.beausoleil@gmail.com> Assigned to: has_and_belongs_to_many habtm
Priority: normal Milestone: 1.0
Component: ActiveRecord Version: 0.14.3
Severity: normal Keywords: habtm has_and_belongs_to_many
Cc:

Description

Has and belongs to many relationships adds a method to add multiple objects at once using only their ID. We have no way of getting that same list back easily. The attached patch handles that, as well as a test.

Why is this a problem ? I'm writing HABTM helper plugin, and it means clients of the HABTM code need to do this:

class Contact < ActiveRecord::Base
  has_and_belongs_to_many :groups

  def group_ids
    self.groups.map {|group| group.id}
  end
end

Of course, that could be done in the plugin itself, but I believe this should be a function of the framework, not of client code.

Attachments

habtm-singular-id-get-method.patch (1.7 kB) - added by François Beausoleil <francois.beausoleil@gmail.com> on 11/17/05 19:12:39.
Tests and implementation to add "collection_singular_ids" query method to habtm relationships
habtm-singular-id-get-method-trunk.patch (3.9 kB) - added by François Beausoleil <francois.beausoleil@gmail.com> on 12/09/05 14:53:16.
Patch against trunk
habtm-singular-id-get-method-stable.patch (4.0 kB) - added by François Beausoleil <francois.beausoleil@gmail.com> on 12/09/05 14:56:17.
Patch against stable branch

Change History

11/17/05 19:12:39 changed by François Beausoleil <francois.beausoleil@gmail.com>

  • attachment habtm-singular-id-get-method.patch added.

Tests and implementation to add "collection_singular_ids" query method to habtm relationships

11/18/05 01:54:10 changed by François Beausoleil <francois.beausoleil@gmail.com>

  • keywords set to habtm has_and_belongs_to_many.

Adding missed keywords

12/09/05 14:53:16 changed by François Beausoleil <francois.beausoleil@gmail.com>

  • attachment habtm-singular-id-get-method-trunk.patch added.

Patch against trunk

12/09/05 14:56:17 changed by François Beausoleil <francois.beausoleil@gmail.com>

  • attachment habtm-singular-id-get-method-stable.patch added.

Patch against stable branch

12/09/05 14:57:06 changed by François Beausoleil <francois.beausoleil@gmail.com>

  • milestone set to 1.0.

Just attached two new patches. They replace the previous one. There's one for stable/, the other one for trunk/.

02/25/06 23:47:11 changed by david

  • status changed from new to closed.
  • resolution set to wontfix.

We want to discourage the use of ids directly, so I don't like the idea of exposing these ids more than is already present in the API. If you need it for your plugin, I'd just implement it there.

04/16/07 18:24:11 changed by francois.beausoleil

Well, this was finally implemented in [5214].