This project is archived and is in readonly mode.

#5660 ✓resolved
Jacques Crocker

ActiveResource should work for non-generated ids

Reported by Jacques Crocker | September 19th, 2010 @ 02:57 AM

ActiveResource should allow you to define a primary key which doesn't get generated on the server.

example:

module Recurly
  class Plan < ActiveResouce::Base
    self.element_name = "plan"
    self.prefix = "/company/"
    self.primary_key = :plan_code
  end
end


new_plan = Recurly::Plan.new(:plan_code => "my_new_plan")
new_plan.save! # performs an update instead of a create

The issue is ActiveResource::Base#new? just looks at whether an id exists or not to decide whether or not to update or create. I think it needs to be a bit smarter and track this flag based on whether the record was actually saved onto the server (or found via a query). If the flag is not set, then it should create the record.

Comments and changes to this ticket

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>

Referenced by

Pages