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.

Fixnum and String assignment support for belongs to and has one writers.

#2321

Attached is a patch that allows one to assign a Fixnum or String to a belongs_to or has_many association. An example would be good:

class Firm; has_one :account; end
class Account; belongs_to :firm; end

apple = Firm.create("name" => "Apple")
citibank = Account.create("credit_limit" => 10)

citibank.firm = apple.id
assert_equal apple.id, citibank.firm_id

# in reverse
apple.account = citibank.id

Obviously the utility isn't apparent in the examples (taken from the test cases). It rears its head when you're passing in an ID via a parameter hash such as from a <select/>. It also works around the stale associations you end up with when you assign an *_id which can make your callbacks and validations a snafu.

Reported by Nolan Eakins · March 24th, 2009 @ 01:46 AM

State: stale
Milestone: 3.x
Assigned to: Michael Koziarski Michael Koziarski
Importance: none

Activity

  1. Nolan Eakins
    Nolan Eakins
    • Assigned user set to Pratik

    March 24th, 2009 @ 02:07 AM

  2. Pratik
    Pratik
    • Title changed from [PATCH] AR: Fixnum and String assignment support for belongs to and has one (many, I wish) writers. to Fixnum and String assignment support for belongs to and has one (many, I wish) writers.

    May 18th, 2009 @ 08:15 PM

  3. Pratik
    Pratik
    • Title changed from Fixnum and String assignment support for belongs to and has one (many, I wish) writers. to Fixnum and String assignment support for belongs to and has one writers.

    May 18th, 2009 @ 08:18 PM

  4. Pratik
    Pratik
    • Assigned user changed from Pratik to Michael Koziarski

    I'm not sure I see a lot of value here. But Koz might have something better to say.

    May 18th, 2009 @ 08:19 PM

  5. sneakin
    sneakin

    I also extended the select helper to accept an array of records instead of an a array of pairs. To get the selected value I had to drop the "_id", forcing the need or the writter to accept an id. I may have made a ticket with that change.

    May 19th, 2009 @ 12:10 AM

  6. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  7. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open
    • Importance changed from to

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:40 PM

  8. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:40 PM