This project is archived and is in readonly mode.

#2321 ✓stale
Nolan Eakins

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

Reported by Nolan Eakins | March 24th, 2009 @ 01:46 AM | in 3.x

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.

Comments and changes to this ticket

  • Nolan Eakins

    Nolan Eakins March 24th, 2009 @ 02:07 AM

    • Assigned user set to “Pratik”
  • Pratik

    Pratik May 18th, 2009 @ 08:15 PM

    • 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.”
  • Pratik

    Pratik May 18th, 2009 @ 08:18 PM

    • 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.”
  • Pratik

    Pratik May 18th, 2009 @ 08:19 PM

    • 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.

  • sneakin

    sneakin May 19th, 2009 @ 12:10 AM

    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.

  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:40 PM

    • 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.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:40 PM

    • State changed from “open” to “stale”

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