Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • lucuma 261 posts 563 karma points
    Nov 05, 2010 @ 20:58
    lucuma
    0

    Generic Strategy for 1 to many relationships

    Can someone explain what a good generic strategy is for doing one to many relationships.   A good example would be something like a portfolio page where you have:

    Something like this
    Portfolios
    -Category 1
    -- Example A (name, description, photo(s))
    -- Example B (name, description, photo(s))
    -Category 2
    -- Example C
    -- Example D
    -- Example A
    -Category 3
    -- Example C
    -- Example B

    These are all roughly document types but I just can't seem to figure out how to do a relationship like this?

    Thanks in advance.

  • lucuma 261 posts 563 karma points
    Nov 05, 2010 @ 21:22
    lucuma
    0

    I tried to change the title but it won't save - I meant to put Many to Many relationships.

  • Kouzzmitch 13 posts 36 karma points
    Mar 20, 2011 @ 10:55
    Kouzzmitch
    1

    I did it in this way, You create documents separately. So You will have

    Categories
    -Category 1
    -Category 2
    -Category 3

    Portofolio
    -Example a
    -Example b
    -Example c

    Create Data type of Ultimate Picker which ParentID is fixed to ID of Category? and add this data type to Examples.

    When you would like to put all examples in one place by category you will do it in xslt like this

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [  <!ENTITY nbsp "&#x00A0;">]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

      <xsl:output method="xml" omit-xml-declaration="yes"/>

      <xsl:param name="currentPage"/>
        <xsl:variable name="previewChars" select="255"/>
        <xsl:param name="limitNumber" select="macro/limitNumber"/>  

        <xsl:template match="/">
          <xsl:choose>
    ...
            <xsl:when test="local-name($currentPage)='Service'">
              <xsl:variable name="preNodes">
                <xsl:for-each select="$currentPage/ancestor-or-self::*//Service">
                  <xsl:if test="contains(current()/@path,concat(',',$currentPage/@id))">
                    <xsl:copy-of select="$currentPage/ancestor-or-self::*//Item[@isDoc and string(umbracoNaviHide)!='1' and contains(itemServices,current()/@id)]" />
                  </xsl:if>
                </xsl:for-each>
              </xsl:variable>
              <xsl:variable name="nodes" select="msxml:node-set($preNodes)/Item[@isDoc and string(umbracoNaviHide)!='1']" />
              <xsl:if test="count($nodes)&gt;0">
                <h2>We did in Service</h2>
                <xsl:call-template name="itemsArray">
                  <xsl:with-param name="arrayNodes" select="$nodes[not(.=following::Item)]"/>
                  <xsl:with-param name="showPartner" select="1"/>
                  <xsl:with-param name="showServices" select="0"/>
                </xsl:call-template>
              </xsl:if>
            </xsl:when>
    ...
          </xsl:choose>
        </xsl:template>
        
      <xsl:template name="itemsArray">
        <xsl:param name="arrayNodes"/>
        <xsl:for-each select="$arrayNodes">
          <xsl:sort select="umbraco.library:FormatDateTime(itemDate, 'yyyyMMddhhmmss')" data-type="number" order="descending" />
          <xsl:if test="position() &lt;= $limitNumber">
            <div>
               
    <h3>
                     <xsl:value-of select="@nodeName"/>
                </h3>
                <p>
                  <xsl:variable name="Text" select="umbraco.library:StripHtml(current()/bodyText)" />
                  <xsl:value-of select="concat(substring($Text, 1, $previewChars),substring-before(substring($Text, $previewChars+1, 10),' '))" disable-output-escaping="yes"/>
                  <xsl:if test="string-length($Text) &gt; $previewChars">...</xsl:if>
                </p>
              </div>
            <xsl:if test="(position() mod 2)=0 or position()=last()"><hr/></xsl:if>
          </xsl:if>
        </xsl:for-each>
      </xsl:template>
        
    </xsl:stylesheet>
  • Kouzzmitch 13 posts 36 karma points
    Mar 20, 2011 @ 10:57
    Kouzzmitch
    1

    But if your web getting large youll have to seek for Relationships API

    Umbraco Relation API ยป Hendy's Blog

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Mar 21, 2011 @ 10:56
    Hendy Racher
    0

    Hi Kouzzmitch,

    FYI, you can automatically create relations from the multipicker selected values using the MultiPicker Relations datatype in uComponents - this can be especially useful for reverse lookups, eg, find all Examples in Category 1.

    Cheers,

    Hendy

  • Kouzzmitch 13 posts 36 karma points
    Mar 21, 2011 @ 19:19
    Kouzzmitch
    1

    Thanks Hendy

    You should post link not to package but to your blog article Umbraco MultiPicker Relations because it much more extended.

    Please correct me if i did't catch technics of your proposal

    1. we should add Relation Types package and uComponents package for Multipicker relations to the website

    2. we should create relationships for Category to Example and Example to Category using Relations Types package

    3. Create custom DataType from Multi Node Tree Picker control (for example, complete list of controls in Hendy's blok follow previous link)  and set up Xpath in its properties to select only \\Category datatype.

    4. We should create new datatype from MultiPicker relations control and configure it to use Example to Category, and create second datatype to use Category to Example relation.

    5. AddDatattypes from 3,4 to Example doctype

     

    You wrote how to retrieve related items from c#

    int colourNodeId = 123;
    RelationType relationType = RelationType.GetByAlias("coloursToProduct");
    Relation[] relations = Relation.GetRelations(colourNodeId , relationType);

    Node productNode;
    foreach (Relation relation in relations)
    {
    productNode = new Node(relation.Child.Id);
    }

    but i have not found just how to use it from xslt

     

     

     

     

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Mar 21, 2011 @ 21:34
    Hendy Racher
    0

    Thanks Kouzzmitch,

    I think you've got it spot on :)

    Just to clarify:

    2) if you just want to know that a Category is related to an Example (or via-se-versa) but the direction isn't important then you could use a single Bidirectional Relation Type instead.

    Here's the Xslt example (it went missing from the blog post somehow)

    <xsl:variable name="colourNodeId" select="123" />
    <xsl:variable name="relations" select="umbraco.library:GetRelatedNodesAsXml($colourNodeId)//relation[@typeName='Colours to Product']" />

    <xsl:for-each select="$relations">
     
    <xsl:value-of select="./node/@nodeName" />
    </xsl:for-each>

    (btw, there are some extension methods in uQuery for working with the RelationType object)

    HTH,

    Hendy

     

     

  • lucuma 261 posts 563 karma points
    Mar 21, 2011 @ 22:14
    lucuma
    0

    Been a good discussion. My only beef with the UI is that there is no good way to show an administrator on the tree how items are related (that I know of). It would be great if there was a "tree view" that showed this so that you could actually see at a glance where the items are without having to open different documents. Anyways, I'm using the Multinode Picker for now since the project I'm on isn't too difficult.

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Mar 21, 2011 @ 22:32
    Hendy Racher
    0

    Hi Lucuma,

    That's one of the really nice things about wiring up MultiPickers to RelationTypes (especially a reverse Parent to Child RelationType) as it's easy to use the Relations as a data source for a custom tree. (humm.. how about being able to automatically configure such trees somehow, and which section would they go in ?)

    The RelationTypes package (the version on CodePlex) allows you to see relations for a given RelationType.

    HTH,

    Hendy

Please Sign in or register to post replies

Write your reply to:

Draft