Category newCategory = new Category(); newCategory.setName("Test Category"); newCategory.setItems(new ArrayList<Reference>()); mCategory = Collections.singletonList(mInventoryConnector.createCategory(newCategory)); Item newItem = new Item(); newItem.setName("Test Item"); newItem.setCategories(mCategory); newItem.setPrice(100L); mInventoryConnector.createItem(newItem);
The category is created.
The item is created but is not tagged with the category. Is there a bug in the createItem() method or am I doing something wrong?
As a workaround we are now creating our items first then creating the category and passing in the item list;
Item newItem = new Item(); newItem.setName("Test Item"); newItem.setPrice(100L); newItem = mInventoryConnector.createItem(newItem); Category newCategory = new Category(); newCategory.setName("Test Category"); List<Reference> items = new ArrayList<>(); items.add(new Reference(newItem.getJSONObject())); newCategory.setItems(items); mInventoryConnector.createCategory(newCategory);
I was curious why the .setItems() method takes a list of Reference rather than a list of Item? Is my technique of converting the Item to a Reference OK/the best?
Thanks