How to update content without lost relationships?

13 views
Skip to first unread message

mvelasco

unread,
Dec 22, 2017, 11:40:02 AM12/22/17
to dotCMS User Group
I have two content types and a relationship 1: N
Content types:  Promotion (parent), Version (child)
Relationship Promotion-Version

I didn't have any problem saving "Versions" but every time I save a Promotion I lost all previous relationships with Versions. 
As documentation says https://dotcms.com/docs/latest/save-content-using-the-rest-api "When updating content using the REST API, you must submit all relationships for a piece of content each time you update the content."

I tried with:

  1. {
    1. Promotion-Version:"+identifier:(11f3a625-ec65-4414-9c97-84e8e6dc8ede && 35f3ed74-06f2-4463-a4e9-a37823008c9a)"
    2. acquisitionoffer:"True"
    3. domain:"domain-1"
    4. id:"Test 1.3"
    5. identifier:"76df92aa-a443-41bd-9818-8afddbe860c6"
    6. stInode:"c9cebf62-a542-4197-8f7d-55e004ab8393"
    7. type:"Casino"
 }

11f3a625-ec65-4414-9c97-84e8e6dc8ede and 35f3ed74-06f2-4463-a4e9-a37823008c9a are two version of promotion 76df92aa-a443-41bd-9818-8afddbe860c6 But this didn't work.

Any ideas?
Thanks!

John Michael Thomas

unread,
Dec 26, 2017, 8:28:18 PM12/26/17
to dotCMS User Group
So it looks like your query for the relationships field is incorrect.  You're using the AND (&&) operator, which means that the query will only match content where the identifier is BOTH of those ids AT THE SAME TIME.  Which obviously can't happen.  Try changing the `&&` to `||` (or just removing it completely, since if you don't have that operator it will treat a space as an OR anyway).

One tip in general when working with queries: Try running the query in the Query Tool (in the dotCMS back-end) first to make sure it returns what you expect it to.  If you run the query you're using now, you should find that it returns no results.  Then try running it after removing the `&&` and make sure it gets back the two content items you expect.

(Note that you can just as easily use the REST API to submit the query using a REST call instead of using the Query Tool, but the Query Tool is generally faster to experiment with since it's interactive).

Hope it helps.
Reply all
Reply to author
Forward
0 new messages