This project is archived and is in readonly mode.
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
-
Jacques Crocker September 19th, 2010 @ 04:22 AM
- Tag changed from activeresource, active_resource, resource to activeresource, active_resource, patched, resource
Was a fairly simple fix.
Patched via the topic branch:
http://github.com/railsjedi/rails/commits/nongeneratedidsPull request sent. Please review and merge if possible
-
gnufied September 22nd, 2010 @ 05:20 PM
Couple of things:
- Your pull request, doesn't merge cleanly agains master
branch.
- You have added:
@@@ ruby require 'fixtures/address' @@@ But the file isn't in your patch. - Probably you are better off, creating a patch using format-patch rather than sending a pull request.
- Your pull request, doesn't merge cleanly agains master
branch.
-
Jacques Crocker September 22nd, 2010 @ 10:38 PM
gnufied: thanks for the heads up. i was trying to juggle 2 patches at the same time and got confused in splitting up the branches. has been fixed now: http://github.com/railsjedi/rails/tree/nongeneratedids
I do think a topic branch is the right approach as I can make fixes like this easily without having to regenerating a patch.
Please retest if you can. I just verified cherry picking it into origin/master and everything ran silky smooth :-)
-
Repository September 25th, 2010 @ 10:16 AM
- State changed from new to resolved
(from [ee5ef67c443407f616feef3a8cade8ba3a9d6ef0]) Allow ActiveResource to work with non-generated ids [#5660 state:resolved]
This commit updates new? so that it knows whether or not the record was actually new or not, and doesn't rely solely on the presence of id. This enables the ability to set a custom primary_key that is not autogenerated by the server.
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/ee5ef67c443407f616feef3a8cade8... -
Andrea Campi October 11th, 2010 @ 07:23 AM
- Tag changed from activeresource, active_resource, patched, resource to activeresource, active_resource, patch, resource
bulk tags cleanup
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>
People watching this ticket
Referenced by
- 5660 ActiveResource should work for non-generated ids (from [ee5ef67c443407f616feef3a8cade8ba3a9d6ef0]) Allow A...