<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Content modelling - normalisation in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/content-modelling-normalisation/m-p/328287#M15288</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Is is possible to model a object hierarchy for content?&lt;/P&gt;
&lt;P&gt;For example, say I am modelling a News Article and all News Articles have an author and we'd like to store the author's first name, surname and their base location.  The same author may write many of these articles.  Is there a way to select an author which has already been created instead of creating the same author details more than once?&lt;/P&gt;
&lt;P&gt;Can I set up a widget on my creation\edit screens for News Articles to browse existing people records for selection?&lt;/P&gt;
&lt;P&gt;Thanks,
Lynn&lt;/P&gt;</description>
    <pubDate>Wed, 07 May 2014 16:00:10 GMT</pubDate>
    <dc:creator>Lynn_</dc:creator>
    <dc:date>2014-05-07T16:00:10Z</dc:date>
    <item>
      <title>Content modelling - normalisation</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/content-modelling-normalisation/m-p/328287#M15288</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Is is possible to model a object hierarchy for content?&lt;/P&gt;
&lt;P&gt;For example, say I am modelling a News Article and all News Articles have an author and we'd like to store the author's first name, surname and their base location.  The same author may write many of these articles.  Is there a way to select an author which has already been created instead of creating the same author details more than once?&lt;/P&gt;
&lt;P&gt;Can I set up a widget on my creation\edit screens for News Articles to browse existing people records for selection?&lt;/P&gt;
&lt;P&gt;Thanks,
Lynn&lt;/P&gt;</description>
      <pubDate>Wed, 07 May 2014 16:00:10 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/content-modelling-normalisation/m-p/328287#M15288</guid>
      <dc:creator>Lynn_</dc:creator>
      <dc:date>2014-05-07T16:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: Content modelling - normalisation</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/content-modelling-normalisation/m-p/328288#M15289</link>
      <description>&lt;P&gt;If I understand correctly:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You would like to store the author's first name, last name and base location in each article?&lt;/LI&gt;
&lt;LI&gt;Or you just want to reference the author?&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;In both case, here is something that can achieve this. It should a blog actually because it's a long, long answer, but it will be faster to write an answer here ;-).&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Have an &lt;CODE&gt;Author&lt;/CODE&gt; document type. with author:first_name, etc.&lt;/LI&gt;
&lt;LI&gt;(Create some authors anywhere you wish)&lt;/LI&gt;
&lt;LI&gt;In &lt;CODE&gt;NewsArticle&lt;/CODE&gt; (or in an inherited schema), add the &lt;CODE&gt;author_ref&lt;/CODE&gt; field, which will hold the id of the related &lt;CODE&gt;Author&lt;/CODE&gt; document. If you plan to query the &lt;CODE&gt;NewsArticle&lt;/CODE&gt; on the author name, first name or location, then you must also add the corresponding fields (maybe &lt;CODE&gt;newsarticle:author_first_name&lt;/CODE&gt;, &lt;CODE&gt;newsarticle:author_last_name&lt;/CODE&gt; and &lt;CODE&gt;newsarticle:uthor_base_location&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;In a &lt;CODE&gt;NewsArticle&lt;/CODE&gt; creation layout, add a "Single Document Suggestion" widget and let all the properties with their default values except:
&lt;UL&gt;
&lt;LI&gt;NXQL Query, enter: &lt;CODE&gt;SELECT * FROM Author WHERE author:last_name LIKE ?&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;Possibly, for quick testing and with few authors, I also set "Minimum characters" to 0&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;So, at this step, you can test with:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;(update your Studio config on the server)&lt;/LI&gt;
&lt;LI&gt;Create some Author&lt;/LI&gt;
&lt;LI&gt;create one NewsArticle and use the single document suggestion document to select an author&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Now, if you want to query &lt;CODE&gt;NewsArticle&lt;/CODE&gt; on author's first name or last name or both, you have to duplicate the values:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Create a new Event Handler. Say "NewsArticle_AboutToCreate"&lt;/LI&gt;
&lt;LI&gt;Select the "About to Create" event&lt;/LI&gt;
&lt;LI&gt;Select &lt;CODE&gt;NewsArticle&lt;/CODE&gt; as "Current document has one of the type"&lt;/LI&gt;
&lt;LI&gt;Select "Mutable document" as "Current document is"&lt;/LI&gt;
&lt;LI&gt;Create a new chain, say "NewsArticle_AboutToCreate"&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Here is this chain:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;1. Fetch &amp;gt; Context Document(s)
2. Push &amp;amp; Pop &amp;gt; Push Document
3. Fetch &amp;gt; Document
    value: @{Document["newsarticle:author_ref"])
4. Execution Context &amp;gt; Set Context Variable
    name: firstName
    value: @{Document["author:first_name"]}
5. Execution Context &amp;gt; Set Context Variable
    name: lastName
    value: @{Document["author:lasst_name"]}
6. Execution Context &amp;gt; Set Context Variable
    name: baseLoc
    value: @{Document["author:base_location"]}
7. Push &amp;amp; Pop &amp;gt; Pop Document
8. Document &amp;gt; Update properties
    properties: newsarticle:author_first_name=@{firstName}
                newsarticle:author_last_name=@{lastName}
                newsarticle:author_base_location=@{baseLoc}
    save: UNCHECKED
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Some explanations on the lines:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Line #1: We need to Push/Pop the original document, because we are going to cvhange the context document when getting the &lt;CODE&gt;Author&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;Line #2: The query on &lt;CODE&gt;Author&lt;/CODE&gt; uses the id stored by the user when selecting an author via the suggestion widget&lt;/LI&gt;
&lt;LI&gt;Lines #5-7: We store the values of &lt;CODE&gt;Author&lt;/CODE&gt; in context variables, that will be used when saving these value in the &lt;CODE&gt;NewsArticle&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;Line 7: We make original &lt;CODE&gt;NewsArticle&lt;/CODE&gt; the current context document&lt;/LI&gt;
&lt;LI&gt;Line #8: And update it's field&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;It is very important to leave the "Save" box unchecked&lt;/STRONG&gt;, because this chain is called in the context of an "About to create" event. It means nuxeo will save the document after the call, and forcing it to save it "now" will lead to the hell of erros in server.log &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Now, you can also query on articles based on the author. Either via it's ref. or, if you build a custom "Faceted search" for example, by using the fields (&lt;CODE&gt;news article:author_last_name&lt;/CODE&gt; etc.), or via NXQL (&lt;CODE&gt;SELECT * FROM Document WHERE dcm:primaryType = "NewsArticle" AND news article:author_last_name = "TheAuthorLastName"&lt;/CODE&gt;), or. etc.&lt;/P&gt;</description>
      <pubDate>Tue, 13 May 2014 23:27:53 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/content-modelling-normalisation/m-p/328288#M15289</guid>
      <dc:creator>ThibArg_</dc:creator>
      <dc:date>2014-05-13T23:27:53Z</dc:date>
    </item>
  </channel>
</rss>

