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

Fixing hydrator issue when relationship is not included #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

BahaaAlhagar
Copy link

I was trying to use DocumentHydrator to hydrate incoming request

I found out an issue on the Hydrator relationship is not included it gets ignored

consider this example

{
	"data": {
		"id": "",
        "type": "used_car",
		"attributes": {
			"year": 1972,
            "status": "draft"
		},
		"relationships": {
			"brand": {
				"data": {
					"id": "9",
					"type": "brand"
				}
			},
			"carBodyShape": {
				"data": {
					"id": "2",
					"type": "car_body_shape"
				}
			},
			"carModel": {
				"data": {
					"id": "3",
					"type": "car_model"
				}
			},
			"carGrade": {
				"data": {
					"id": "4",
					"type": "car_grade"
				}
			},
            "country": {
				"data": {
					"id": "4",
					"type": "country"
				}
			},
            "city": {
				"data": {
					"id": "4",
					"type": "city"
				}
			},
            "area": {
				"data": {
					"id": "4",
					"type": "area"
				}
			},
            "more_licenses": {
				"data": [
					{
						"id": "bb4c1dba-3d9d-4df1-85d0-7cb28wec4e135",
						"type": "used_car_license"
					},
					{
						"id": "bb4c1dba-3d9d-4df1-85d0-7cb28ewc4e136",
						"type": "used_car_license"
					}
				]
			},
			"licenses": {
				"data": [
					{
						"id": "bb4c1dba-3d9d-4df1-85d0-7cb28ec4e135",
						"type": "used_car_license"
					},
					{
						"id": "bb4c1dba-3d9d-4df1-85d0-7cb28ec4e136",
						"type": "used_car_license"
					}
				]
			},
            "internalImages": {
				"data": [
					{
						"id": "bb4c1dba-3d9d-4df1-85d0-7cb28ec4e135",
						"type": "used_car_image"
					},
					{
						"id": "bb4c1dba-3d9d-4df1-85d0-7cb28ec4e136",
						"type": "used_car_image"
					}
				]
			},
            "externalImages": {
				"data": [
					{
						"id": "bb4c1dba-3d9d-4df1-85d0-7cb28ec4e137",
						"type": "used_car_image"
					},
					{
						"id": "bb4c1dba-3d9d-4df1-85d0-7cb28ec4e138",
						"type": "used_car_image"
					}
				]
			}
		}
	},
	"included": [
		{
			"id": "9",
			"type": "brand",
			"attributes": {
				"title": "repellat"
			}
			
		},
		{
			"id": "bb4c1dba-3d9d-4df1-85d0-7cb28ec4e136",
			"type": "used_car_license",
			"attributes": {
				"file": 1,
				"image_type": "front"
			}
			
		},
		{
			"id": "bb4c1dba-3d9d-4df1-85d0-7cb28ec4e135",
			"type": "used_car_license",
			"attributes": {
				"file": 1,
				"image_type": "back"
			}
		},
        {
			"id": "bb4c1dba-3d9d-4df1-85d0-7cb28ec4e136",
			"type": "used_car_image",
			"attributes": {
				"file": 1,
				"image_type": "internal"
			}
			
		},
		{
			"id": "bb4c1dba-3d9d-4df1-85d0-7cb28ec4e135",
			"type": "used_car_image",
			"attributes": {
				"file": 1,
				"image_type": "internal"
			}
		},
        {
			"id": "bb4c1dba-3d9d-4df1-85d0-7cb28ec4e137",
			"type": "used_car_image",
			"attributes": {
				"file": 1,
				"image_type": "external"
			}
			
		},
		{
			"id": "bb4c1dba-3d9d-4df1-85d0-7cb28ec4e138",
			"type": "used_car_image",
			"attributes": {
				"file": 1,
				"image_type": "external"
			}
		}
	]
}

On the last case all relationships that does not have included data gets removed from serialized to JSON object
carModel, carBodyShape, carGrade will get ignored because it does not included

This updates add an object for each not included relationship while hydrating data
The object will have only id & type

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

Successfully merging this pull request may close these issues.

1 participant