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

Create Node with Multiple FieldCollection Item #1037

Open
julienperrault opened this issue Jul 3, 2018 · 2 comments
Open

Create Node with Multiple FieldCollection Item #1037

julienperrault opened this issue Jul 3, 2018 · 2 comments

Comments

@julienperrault
Copy link

julienperrault commented Jul 3, 2018

Hi,
I want to create a node through the POST route with a proprety named "box".

		$public_fields['box'] = array(
			'property' => 'box',
		);

Box is a FieldCollection. So when i send :

{
 "abc": "def",
 "box": [
		{
			"qty": "2180",
			"item": "potato"
		},
		{
			"qty": "2821",
			"item": "tomato"
		}
]
}

I looking for a node linked with those 2 new items.

When i look in SQL log i found this :

INSERT INTO field_data_box (entity_type, entity_id, revision_id, bundle, delta, language, box_value, box_revision_id) VALUES ('node', '15068', '23455', 'testNode', '0', 'und', '2187', '2180', NULL), ('node', '15068', '23455', 'company_profile', '1', 'und', '2180', '2821', NULL)

So he doesn't create each field collection item. He just try to link with qty values.

@julienperrault julienperrault changed the title Create Taxonomy Term with specific parent Term and Vocabulary Create Node with Multiple FieldCollection Item Jul 4, 2018
@charlie-rushton
Copy link

@julienperrault I know this was a long time, but by ay chance did you manage to solve this one?

@julienperrault
Copy link
Author

@charlie-rushton
Oh indeed, I forgot to close the ticket.
I found a tricky way to do it. First I create a route for each multiple FieldCollection ressources.

During execution:

  • We retrieve the target node and the ids of Multiple FieldCollections (if it is an update of the target node)
  • We update or create the target node (its data only)
  • We create all Multiple FieldCollection Items to link
  • For each Multiple FieldCollection, we create an array of items's id, and update the target node with them.
  • We delete the old linked items.

The big problem is the infinite creation/deletion of this system which leads to an excessive increase in the primary key of the elements.

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

2 participants