We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43199
    • 2 Posts
    Hi guys,

    I'm using migxLoopCollection for a new site idea, but i'm a bit stuck. I have 3 DB tables: Scapes (could be blogs in an other case), Tags and ScapesTags (relational table).

    My scheme looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <model package="scapes" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
    	<object class="Scapes" table="scapes" extends="xPDOSimpleObject">
    
    		
    		<field key="scape_id" dbtype="int" precision="11" phptype="integer" null="false" index="pk"  generated="native" />
    		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
                    <column key="scape_id" collation="A" null="false" />
            </index>
            <composite alias="ScapesTags" class="ScapesTags" local="scape_id" foreign="scape" cardinality="many" owner="local" />
    
    	 	<field key="likes" dbtype="varchar" phptype="string" precision="200" null="false" default=""/>
    	 	<field key="views" dbtype="varchar" phptype="string" precision="200" null="false" default=""/>
    
    	 	<field key="title" dbtype="varchar" phptype="string" precision="100" null="false" default=""/>
    	 	<field key="author" dbtype="varchar" phptype="string" precision="50" null="false" default=""/>
    	 	<field key="email" dbtype="varchar" phptype="string" precision="50" null="false" default=""/>
    	 	<field key="description" dbtype="longtext" phptype="longtext" null="false" default=""/>
    	 	<field key="link" dbtype="varchar" phptype="string" precision="50" null="false" default=""/>
    
    	 	<field key="Dimensions" dbtype="varchar" phptype="string" precision="20" null="false" default=""/>
    	 	<field key="Volume" dbtype="varchar" phptype="string" precision="20" null="false" default=""/>
    	 	<field key="Background" dbtype="varchar" phptype="string" precision="50" null="false" default=""/>
    	 	<field key="Lighting" dbtype="varchar" phptype="string" precision="50" null="false" default=""/>
    	 	<field key="Filtration" dbtype="varchar" phptype="string" precision="50" null="false" default=""/>
    	 	<field key="Substrate" dbtype="varchar" phptype="string" precision="50" null="false" default=""/>
    	 	<field key="CO2" dbtype="varchar" phptype="string" precision="50" null="false" default=""/>
    	 	<field key="Fertilization" dbtype="varchar" phptype="string" precision="50" null="false" default=""/>
    	 	<field key="Plants" dbtype="varchar" phptype="string" precision="50" null="false" default=""/>
    	 	<field key="Hardscape" dbtype="varchar" phptype="string" precision="50" null="false" default=""/>
    	 	<field key="Fish" dbtype="varchar" phptype="string" precision="50" null="false" default=""/>
    	 	<field key="Additional info" dbtype="longtext" phptype="longtext" null="false" default=""/>
    
    	 	<field key="useragent" dbtype="varchar" phptype="string" precision="200" null="false" default=""/>
    
    	 	<!--
    			SYSTEM
    		-->
    		<field key="createdon" dbtype="timestamp" phptype="timestamp" null="true" default="CURRENT_TIMESTAMP"/>
    	    <field key="createdby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
    	    <field key="editedon" dbtype="datetime" phptype="datetime" null="true"/>
    	    <field key="editedby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
    	    <field key="deleted" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
    	    <field key="published" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
    	    <aggregate alias="CreatedBy" class="modUser" local="createdby" foreign="id" cardinality="one" owner="foreign"/>
    	    <aggregate alias="EditedBy" class="modUser" local="editedby" foreign="id" cardinality="one" owner="foreign"/>
    
    	</object>
    
    
    
    
    	<object class="Tags" table="tags" extends="xPDOObject">
            <field key="tag_id" dbtype="int" precision="11" phptype="integer" null="false" index="pk"  generated="native" />
            <field key="name" dbtype="varchar" precision="255" phptype="string" null="true" />
            <index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
                    <column key="tag_id" collation="A" null="false" />
            </index>
            <composite alias="ScapesTags" class="ScapesTags" local="tag_id" foreign="tag_id" cardinality="many" owner="local" />
    	</object>
    
    
    
    	<object class="ScapesTags" table="scapes_tags" extends="xPDOSimpleObject">
    	        <field key="scape" dbtype="int" precision="11" phptype="integer" null="true" />
    	        <field key="tag" dbtype="int" precision="11" phptype="integer" null="true" />
    	        <index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
    	                <column key="id" collation="A" null="false" />
    	        </index>
    	        <aggregate alias="Tags" class="Tags" local="tag" foreign="tag_id" cardinality="one" owner="foreign" />
    	        <aggregate alias="Scapes" class="Scapes" local="scape" foreign="scape_id" cardinality="one" owner="foreign" />
    	</object>
    
    
    
    </model>
    


    My migxLoopCollections snippet call:

    [[!migxLoopCollection?
                &packageName=`scapes`
                &classname=`Scapes`
                &prefix=`brnln_`
                &tpl=`scapesTpl`
                &limit=`20`
                &cache=`0`
                &sortConfig=`[{"sortby":"scape_id","sortdir":"ASC"}]`
                &where=`{"ScapesTags.tag:IN":[ 15,9,10 ]}`
                &joins=`[{"alias":"ScapesTags"}]`
            ]]
    


    The problem:
    My snippet call always returns 1 result, no matter what... But if I print [[+total]] it gives me the correct amount of results.

    I hope someone can help me out with this because i'm really stuck for the moment.

    Greets!

    This question has been answered by Bruno17. See the first response.

    • discuss.answer
      • 4172
      • 5,888 Posts
      does it work with

      &placeholdersKeyField=`scape_id`
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 43199
        • 2 Posts
        Quote from: Bruno17 at Mar 29, 2015, 01:54 PM
        does it work with

        &placeholdersKeyField=`scape_id`

        Wow, that did the trick!
        Could you explain why? I didn't see this property in any examples.

        Thank you Bruno!!
          • 4172
          • 5,888 Posts
          migxLoopCollection does create an output-array before rendering.
          By default, it is using the field 'id' for the array-keys.
          In your case, this is allways the same key, because you haven't a field with name 'id'.
          This ends up with only one item in the array.
          With placeholdersKeyField you can define the field, which to use for the array-key.
          The name 'placeholdersKeyField', because you can output all items to placeholders with &toSeperatePlaceholders, where the key of the placeholders is the value of that field.
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!