How to update content without lost relationships?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to update content without lost relationships?

mvelasco
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!

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/aa58c3a7-29be-496b-bd6e-d1cd88d8f5ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to update content without lost relationships?

John Michael Thomas
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.

On Friday, December 22, 2017 at 8:40:02 AM UTC-8, mvelasco wrote:
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 <a href="https://dotcms.com/docs/latest/save-content-using-the-rest-api" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdotcms.com%2Fdocs%2Flatest%2Fsave-content-using-the-rest-api\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH-c00glcETbGGwnthRDkuCX_xIqg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdotcms.com%2Fdocs%2Flatest%2Fsave-content-using-the-rest-api\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH-c00glcETbGGwnthRDkuCX_xIqg&#39;;return true;">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!

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/18822290-1284-4aa9-9626-5310aa88c41f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.