Skip to content
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

Not all prefix parameters specified #166

Open
egoholic opened this issue Feb 24, 2016 · 7 comments
Open

Not all prefix parameters specified #166

egoholic opened this issue Feb 24, 2016 · 7 comments

Comments

@egoholic
Copy link

I have relation belongs_to for all parent association but I got the "Not all prefix parameters specified" error when try to create/update entity. Could anyone explain how I should define associations to make POST request on entityAs/:entityA_id/entityBs/entityB_id/entityCs/entityC_id/entityDs?

Now for EntityD I have:

  belongs_to :entityA
  belongs_to :entityB
  belongs_to :entityC

For now I can successfuly get EntityDs of EntityC, but I can't create or update them.

@JohnSmall
Copy link

I've got this problem as well. I can't work out how to add records that have a belongs_to relationship defined in the class.

@Genkilabs
Copy link

Yep, even in the more simple case of Content belongs_to ContentType, I can include the :content_type_id in my created Content < JsonApiClient::Resource object, and it will correctly route to .../content_types/:content_type_id/contents on a POST. However the default behavior seems to not include actually setting the content_type_id attribute on the created object.

Either it creates params like {"data"=>{"type"=>"contents", "attributes"=>{"content-type-id"=>1, "status"=>"Live"}}, "content_type_id"=>"1"} as seen in #258 which simply returns "Param not allowed"
OR
If you exclude the foreign key in the 'attributes' hash, then the default behavior now ignores the relation and adds an error to the created object's errors hash like {"title"=>"must exist", "detail"=>"content-type - must exist", "code"=>"100", "source"=>{"pointer"=>"/data/relationships/content-type"}, "status"=>"422"}

@Hitesh-bigscal
Copy link

Same issue for me when I use polymorphic association.

@adamdullenty
Copy link

adamdullenty commented Sep 26, 2018

Is there any solution or workaround for this please? We used to use an early version of the gem (1.1.1) and we didn't have any issues. After upgrading to 1.5.3 we started seeing this "Not all prefix parameters specified" issue when trying to update a child resource.

@senid231
Copy link
Member

senid231 commented Oct 2, 2018

Hi @egoholic @JohnSmall @Genkilabs @Hitesh-bigscal @adamdullenty

I've reproduced your issue on version 1.5.3, but in 1.6.0 fixed
You can upgrade to 1.6.0 but keep in mind that this version has one breaking change that could affect you
(take a look at release notes)

class TestResource < JsonApiClient::Resource
  self.site = "http://example.com/"

  def self.key_formatter
    JsonApiClient::DasherizedKeyFormatter
  end

  def self.route_formatter
    JsonApiClient::UnderscoredKeyFormatter
  end
end

class MultiWordParent < Formatted
end

class MultiWordChild < Formatted
  belongs_to :multi_word_parent
end

class BelongsTo < MiniTest::Test
  def test_belongs_to_urls_create_record
    stub_request(:post, 'http://example.com/multi_word_parents/1/multi_word_children').
        with(headers: { content_type: 'application/vnd.api+json', accept: 'application/vnd.api+json' }, body: {
            data: {
                type: 'multi_word_children',
                attributes: {
                    foo: 'bar',
                    'multi-word-field': true
                }
            }
        }.to_json)
        .to_return(headers: { content_type: 'application/vnd.api+json' }, body: {
            data: {
                    id: '2',
                    type: 'multi_word_children',
                    attributes: {
                        foo: 'bar',
                        'multi-word-field': true
                    }
                }
        }.to_json)

    record = MultiWordChild.new(multi_word_parent_id: 1, foo: 'bar', multi_word_field: true)
    result = record.save
    assert result
    assert_equal('2', record.id)
  end
end

@senid231
Copy link
Member

senid231 commented Oct 3, 2018

we have this issue fixed in 1.6.0

to make it work in 1.5.3 you need to add prefix parameter to read_only_attributes

@Genkilabs in your case it could be something like:

class BaseResource < JsonApiClient::Resource
  self.site = "http://example.com/"
end

class ContentType < BaseResource
end

class Content < BaseResource
  belongs_to :content_type
  self.read_only_attributes = read_only_attributes + [:content_type_id]
end

@senid231
Copy link
Member

senid231 commented Oct 3, 2018

@egoholic you have a very strange case but if I think if you add [:entity_a, :entity_b, :entity_c] to read_only_attributes it will work too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants