remi / her

Her is an ORM (Object Relational Mapper) that maps REST resources to Ruby objects. It is designed to build applications that are powered by a RESTful API instead of a database.
MIT License
2.05k stars 322 forks source link

Can't destroy through association. #91

Open yonahforst opened 11 years ago

yonahforst commented 11 years ago
class Configuration
  include Her::Model
  has_many :publish_sets
end

class PublishSet
  include Her::Model
  belongs_to :configuration
end

This association works as expected for get requests:

Configuration.find(1234).publish_sets
GET .../configurations/1234/publish_sets

but for delete requests:

Configuration.find(1234).publish_sets.first.destroy
DELETE .../publish_sets/5678

I need to make it so that delete requests use the full nested url DELETE .../configurations/1234/publish_sets/5678

I tried setting collection_path("/configurations/:configuration_id/publish_sets") but the publish_set objects i get back from the api don't have the configuration_id param, only a configuration object.

Is there anyway to do this kind of delete through the association instead of a delete_raw (how i'm doing it now)

remi commented 11 years ago

No, unfortunately setting collection_path("/configurations/:configuration_id/publish_sets") is the right way to do it.

I’ll check if there’s a way we could add support for intersting path parameters back into the fetched resource’s attributes when her initializes it.

yonahforst commented 11 years ago

thanks, that would be amazing.

I'm not sure how this API has their models set up, maybe has_many :through, or polymorphic. In any case, they don't return the relation id, rather the entire object. would it make sense to be able to do something like:

 collection_path("/configurations/#{configuration.id}/publish_sets")

Also, I noticed that every object has its own url embedded as an attribute.

#<Skytap::Configuration(configurations/799324) id="799324" url="https://cloud.skytap.com/configurations/799324" name="234921" error="" runstate="stopped" suspend_on_idle=1800 routable=false .....>

I don't know if this is standard practice with REST APIs. If it is, would it make sense to allow the objects path to be inferred from the object itself (url attribute)?

billc commented 11 years ago

I am having a similar issue with attempting to destroy_existing on a nested resource. Has any progress been made to address this issue?

billc commented 11 years ago

@joshblour Do you have a gist of how you used delete_raw as a work around?