Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Support for String Lists in Mass Assignment of Associations via assocation_ids=

#2032

Currently, ActiveRecord's assocation_name_ids= will eat multiple ids if they're passed in a single string such as ["1,2,3,4"].

When it sees the array, it takes the first position ("1,2,3,4") and calls to_i. This drops everything after the first noninteger character, which means that only the first id value makes it through.

This can be a desired effect for people who do things like rewrite ids to humanize them (210-United-States) because it will still assassinated the unnecessary parts, but for this particular format for this particular method, it seems appropriate.

When nesting a habtm association inside of another form (object[assocation_ids]), ExtJS and others return the format mentioned above.

This patch looks for that format and translates it into what Rails actually wants.

Reported by jbarket (at sleepunit) · February 21st, 2009 @ 12:16 AM

State: wontfix
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. cainlevy
    cainlevy

    -1

    This doesn't seems like a standard parameter format, nor one that should be standard. And the patch is tiny, yes, but I'd be disinclined to support non-standard ExtJS formats in core.

    Have you considered overriding your own association_ids= setter, or creating an association_ids_for_ext_js= setter? This also seems easily doable as a plugin, if you're concerned about redundant coding.

    February 21st, 2009 @ 07:39 PM

  2. jbarket (at sleepunit)
    jbarket (at sleepunit)

    After discussing this one the mailing list and on IRC, I'm pretty sure you're right. Even though it's harmless, the only other way I see it coming up is stupidity, and I don't want the patch to reward laziness, heh.

    I think integrating it into an ExtJS plugin I'm already fond of is probably the way to go. I could even try and simply override it in JavaScript then.

    Thanks.

    February 21st, 2009 @ 08:07 PM

  3. Eloy Duran
    Eloy Duran
    • State changed from new to wontfix

    February 22nd, 2009 @ 04:41 PM