-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce need to work arounds #337
Comments
Another oddity discovered required a wee bit more work. class Foo < JsonApiClient::Resource
property :fuzz
end
class Bar < JsonApiClient::Resource
has_one :foo
has_many :foos
end
bar = Bar.new
bar.foo = Foo.new(fuzz: "Buzz") #<Foo:@attributes={"type"=>"foos", "fuzz"=>"Buzz"}>
bar.foo #<Foo:@attributes={"type"=>"foos", "id"=>nil}>
bar.foo.fuzz #nil
bar.foos = [Foo.new(fuzz: "Buzz"), Foo.new(fuzz: "Buzz")] #[#<Foo:@attributes={"type"=>"foos", "fuzz"=>"Buzz"}>, #<Foo:@attributes={"type"=>"foos", "fuzz"=>"Buzz"}>]
bar.foos.first.fuzz #nil |
@code-bunny this is not an oddity. Can you give me usecase when you need to access relationship attributes of object which you currently create/update ? |
@senid231 so an example where we would want to access the relationship before committing it is for instance when using a wizard like an order checkout. class Item < JsonApiClient::Resource
property :title
end
class Order < JsonApiClient::Resource
include SomeStepWizard
has_many :items
end
order = Order.new
order.step # 1
order.items = [Item.find(1).first]
order.next_step
# in some view
order.items.each { |item| puts "Thank you for wanting to buy #{item.title}" }
order.save Basically when we assign a resource it should behave in the same was is if we had run an include on the endpoint. This would keep the behaviour consistent as demonstrated in my example. bar = Bar.includes(:foo).find(1).first
bar.foo.hello # "world"
bar = Bar.new
bar.foo = Foo.find(1).first
bar.foo.hello # "world" |
While perhaps better as three separate issue, they are all interconnected so I will group them into one group of bugs.
Custom endpoints don't respond to route_format changes. We have fixed this with
Has one associations has a bug from the latest code change, fixed by applying .underscore
And finally relationship_data_for was falling apart when there was no key? method on the relationship_definition which is triggered by assigning and array to a has_many relation which is fixed by making more if's as I am not too sure of all the inner workings
The text was updated successfully, but these errors were encountered: