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

Upgrade AMS from 0.9 to 0.10 and using Ember Active Model Adapter facing problems in side loading #2394

Open
kannans5 opened this issue Sep 24, 2020 · 3 comments

Comments

@kannans5
Copy link

kannans5 commented Sep 24, 2020

I assume this has been discussed several times already, just want to understand whether sideloading is possible with json adapter or works only with json_api adapter?

Current, I have the config as

ActiveModelSerializers.config.tap do |config|
  config.embed = :ids
  config.embed_in_root = true
end

and after the upgrade, I have changed it to

ActiveModelSerializers.config.adapter = :json
ActiveModelSerializers.config.default_includes = "**" # to include nested resources

Example:
Taking the reference from here
https://api.emberjs.com/ember-data/1.13/classes/DS.ActiveModelAdapter This Adapter expects specific settings using ActiveModel::Serializers, embed :ids, embed_in_root: true which sideloads the records.

Earlier if I have has_many relationship defined in the serializer, I would get the occupations side loaded.

{
	"people": [{
		"id": 1,
		"first_name": "John",
		"last_name": "Doe",
		"occupation_ids": [1]
	}],

	"occupations": [{
		"id": 1,
		"name": "developer"
	}]
}

Now I am getting the response like this

{
	"people": [{
		"id": 1,
		"first_name": "John",
		"last_name": "Doe",
		"occupations": [{
			"id": 1,
			"name": "developer"
		}]
	}]
}

I have read from the other posts, that I could get the occupation_ids using this in the PeopleSerializer

def occupation_ids
  object.occupations.pluck(:id)
end

But how do I sideload the associations, rather than nesting inside the people?

@kannans5 kannans5 changed the title Upgrade AMS from 0.9 to 0.10 and using Ember Active Model Adapter facing problems in embed_in_root Upgrade AMS from 0.9 to 0.10 and using Ember Active Model Adapter facing problems in side loading Sep 24, 2020
@Nerian
Copy link

Nerian commented May 13, 2021

@kannans5 I face the same problem. Did you find a solution?

@pjsanjuan
Copy link

any news or workarounds for this? facing a similar issue.

@bf4
Copy link
Member

bf4 commented Nov 22, 2022

I know someone made an upgrade guide somewhere in the repo or in an issurme but in general I think people found 8, 9, and 10 pretty hard to switch .

That particular ember adapter iirc is pretty ancient at this point

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

4 participants