her
her copied to clipboard
Creating nested resource POST's to wrong URL
I try this (as per the documentation)
class User
include Her::Model
has_many :comments
has_one :role
belongs_to :organization
end
class Comment
include Her::Model
end
When I run this code in the Rails console:
user = User.find(1)
user.comments.create()
The POST request is made to /comments and not /user/1/comments.
The documentation clearly states that the POST request should be done to /user/1/comments. Did I do something wrong here?
+1
+1
The behaviour is wrong but I can't figure out why. I'm new to this codebase but I've been trying to debug this for over an hour now and I just can't find where the path is supposed to be built when creating. It's pretty straight forward for the GET requests but the not for the POST.
There should be something like this happening somewhere in the execution:
path = build_association_path lambda { "#{@parent.request_path(@params)}#{@opts[:path]}/#{id}" }
@remiprev Please take a look if you have a minute. Or just let me know where I should be looking.
Line 43 in lib/model/orm.rb, definitely needs more flexibility. Where it says :_path => request_path. The stubbed out request in the spec in spec/model/associations_spec.rb (line 363-364) seems to indicate that two requests is necessary.
I'm thinking a good fix would be to add a function in lib/her/model/associations/association.rb
that encapsulates the save
method of orm.rb
by building the proper path first and then calling save
. There's already a similar function there that does the same for GET by encapsulating the call in the find
function.
But again I'm new to this codebase and it might already be done somewhere I just can't find it. But I agree with @pfspontus it seems that behaviour in the README is not implemented by looking at the spec.
+1 (merge please)
+1 (merge please)
Is this still a known/unsolved issue?