{"action":"created","issue":{"url":"https://api.github.com/repos/cerebris/jsonapi-resources/issues/386","labels_url":"https://api.github.com/repos/cerebris/jsonapi-resources/issues/386/labels{/name}","comments_url":"https://api.github.com/repos/cerebris/jsonapi-resources/issues/386/comments","events_url":"https://api.github.com/repos/cerebris/jsonapi-resources/issues/386/events","html_url":"https://github.com/cerebris/jsonapi-resources/issues/386","id":101120223,"number":386,"title":"Creating relationship that differs in name from type ","user":{"login":"mmartinson","id":6256333,"avatar_url":"https://avatars.githubusercontent.com/u/6256333?v=3","gravatar_id":"","url":"https://api.github.com/users/mmartinson","html_url":"https://github.com/mmartinson","followers_url":"https://api.github.com/users/mmartinson/followers","following_url":"https://api.github.com/users/mmartinson/following{/other_user}","gists_url":"https://api.github.com/users/mmartinson/gists{/gist_id}","starred_url":"https://api.github.com/users/mmartinson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmartinson/subscriptions","organizations_url":"https://api.github.com/users/mmartinson/orgs","repos_url":"https://api.github.com/users/mmartinson/repos","events_url":"https://api.github.com/users/mmartinson/events{/privacy}","received_events_url":"https://api.github.com/users/mmartinson/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-14T23:12:20Z","updated_at":"2015-08-19T21:42:43Z","closed_at":null,"body":"In the json:api spec there is this example, suggesting that is is possible to post a people resource identifier object to the author relationship. I am trying to so something similar and am getting some different behaviour than I would expect from JR.\r\n\r\n```\r\nPATCH /articles/1/relationships/author HTTP/1.1\r\nContent-Type: application/vnd.api+json\r\nAccept: application/vnd.api+json\r\n\r\n{\r\n  \"data\": { \"type\": \"people\", \"id\": \"12\" }\r\n}\r\n```\r\n\r\nUsing this example, I would expect JR to look up the article and person objects and call something like this ``article.author = person``. This assumes that the article model implements an author association that represents an instance of Person.\r\n\r\nThe example above using the to_one, but assume for example's sake it's a too_many authors, since that's where I've been having the problem.\r\n\r\nIn ``Resource#_create_to_many_links`` this code ``@model.public_send(relationship.type) << related_resource.model`` would call ``article.people`` instead of ``article.author(s)``, since ``relationship.type`` is derived from the ``class_name`` option of the association in the resource class.\r\n\r\nNot sure if this is a bug or a feature and my problem stems from a misunderstanding of the spec. Should the association be modified so that some attribute of the relationship object other than type can be used to make associations, or is there a way to make this work with the options that are currently implemented?\r\n\r\nJust to be clear, what I would like to achieve is for JR to call the name of the relationship in the url as the relationship method on the model, and not the class_name option from the relationship in the JR Resource class. Changing the relationship class name in the resource class to make it work but then have my relationship pointing to a class that doesn't actually exist."},"comment":{"url":"https://api.github.com/repos/cerebris/jsonapi-resources/issues/comments/132797293","html_url":"https://github.com/cerebris/jsonapi-resources/issues/386#issuecomment-132797293","issue_url":"https://api.github.com/repos/cerebris/jsonapi-resources/issues/386","id":132797293,"user":{"login":"lgebhardt","id":29154,"avatar_url":"https://avatars.githubusercontent.com/u/29154?v=3","gravatar_id":"","url":"https://api.github.com/users/lgebhardt","html_url":"https://github.com/lgebhardt","followers_url":"https://api.github.com/users/lgebhardt/followers","following_url":"https://api.github.com/users/lgebhardt/following{/other_user}","gists_url":"https://api.github.com/users/lgebhardt/gists{/gist_id}","starred_url":"https://api.github.com/users/lgebhardt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lgebhardt/subscriptions","organizations_url":"https://api.github.com/users/lgebhardt/orgs","repos_url":"https://api.github.com/users/lgebhardt/repos","events_url":"https://api.github.com/users/lgebhardt/events{/privacy}","received_events_url":"https://api.github.com/users/lgebhardt/received_events","type":"User","site_admin":false},"created_at":"2015-08-19T21:42:43Z","updated_at":"2015-08-19T21:42:43Z","body":"I don't think that's right. I think this would be better solved with an option on the to_many relationship that indicates the method on the model. That way we maintain the independence of the resource from the model methods. The `foreign_key` option was supposed to do this, but it is a bit wonky in that it's used for `_replace_to_many_links` but not `_create_to_many_links`."}}