her icon indicating copy to clipboard operation
her copied to clipboard

Creating nested resource POST's to wrong URL

Open danielstocks opened this issue 10 years ago • 8 comments

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?

danielstocks avatar Apr 16 '14 09:04 danielstocks

+1

brissmyr avatar Apr 22 '14 12:04 brissmyr

+1

ghost avatar Apr 29 '14 14:04 ghost

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.

Chris911 avatar May 01 '14 05:05 Chris911

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.

ghost avatar May 02 '14 12:05 ghost

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.

Chris911 avatar May 02 '14 12:05 Chris911

+1 (merge please)

cseeger avatar Nov 02 '14 02:11 cseeger

+1 (merge please)

araslanov-e avatar May 20 '15 07:05 araslanov-e

Is this still a known/unsolved issue?

nosretep avatar Dec 06 '17 17:12 nosretep