Add support for creating resources with polymorphic has one.#274
Add support for creating resources with polymorphic has one.#274barelyknown wants to merge 5 commits intoJSONAPI-Resources:masterfrom
Conversation
There was a problem hiding this comment.
I'd prefer to see the HasOne check first, then check association.polymorphic? within that block. We could then follow suit for HasMany relationships later.
There was a problem hiding this comment.
Ok, I added that.
|
I'd eventually like to allow restrictions on possible |
|
All in all, this looks like a promising start on polymorphism - nice work @ggordon and @barelyknown! |
|
I'm going to take a crack at support for |
This adds support for the serialization of `has_many` relationships. I'm not sure if it handles every situation that people are imagining but it addresses the primary issue that I saw which was the need to return the correct type for the individual resources. As with the solution for polymorphic `has_one` relationships, you need to add a `Resource` and `Controller` class for each potential type. I didn't address anything new related to creating or updating `has_many` relationships in this commit.
|
That last commit adds polymorphism to the "read" side of |
|
@barelyknown I had merge conflicts in #255 with the Readme, from PR #277, those are probably the same. |
|
Ugh. The conflicts are a mess now. I'll see if I can work it out. |
|
Sorry, I know. I'm going through them now. So if you want to hold off I'll see if I can get it all resolved. |
|
I pushed the new rebase/274 branch up. I hope I got it all correct. All the tests pass, and there are the same two lines that are not covered. |
|
Oh, good. Thanks for doing that - I know that it was a pain! |
|
@barelyknown It was my fault for not merging this earlier. |
|
Thanks! Merged by #288 |
|
@lgebhardt I'm having an issue on Resource definition: Model definition: |
This simply adds to PR https://github.com/cerebris/jsonapi-resources/pull/255 from @ggordon. I added support for creating resources with a polymorphic
has_one. I don't like the code, but I wanted to change as little as possible for now since I need this feature ASAP. We should refactor to handle the creation of allhas_onerelationships the same way (whether or not they're polymorphic), but I think that we can merge prior to that since we'll have good test coverage and the public API feels right.