Condition for Multi Object field

Michael_S
Senior Member
Beiträge: 160
Registriert: Mi 4. Feb 2004, 02:39
Wohnort: London / UK
Kontaktdaten:

Condition for Multi Object field

Beitragvon Michael_S » Di 26. Mär 2013, 20:55

Hi,

How would I construct a condition for a Multi Object field in an Class?

Code: Alles auswählen

http://domain.com/index.php?cat=category1
Class = Node
Field = Node_Category
Type = Multi object
Multi object Class = Category
Multi object's = category1, category2, category3

Class = Category
Field = Category_Name
Type = Text input

For a field with a type of Object I would use the following condition but this is not working for the Multi object field:

Code: Alles auswählen

<we:condition name="my_category">
	<we:conditionAdd field="Category_Name" compare="=" var="cat" type="request" exactmatch="true" />
</we:condition>
And to test the condition:

Code: Alles auswählen

<?php print $my_category; ?>
Result:

((Category_Name COLLATE utf8_bin = "category1") )

Thanks in advance.

Michael.
Production Area
London, UK
http://productionarea.com

WBTMagnum
webEdition Partner
webEdition Partner
Beiträge: 1825
Registriert: Di 7. Mär 2006, 16:50
Wohnort: Wien
Kontaktdaten:

Re: Condition for Multi Object field

Beitragvon WBTMagnum » Mi 27. Mär 2013, 00:52

Hello Michael,

To my knowledge conditions do not support multiobjects natively.

But I think you could use the following workaround:
http://forum.webedition.org/viewtopic.p ... 908#p47908

Background info:
Multiobjects are stored as a serialized string in the database (hint: If you want to, you can have a look in the database and have a look at the values for the multiobject field in an object). The workaround takes advantage of this situation and looks for IDs within a certain pattern.


HTH,
Sascha

ThomasGoebe

Re: Condition for Multi Object field

Beitragvon ThomasGoebe » Mi 27. Mär 2013, 02:53

Hi Michael,

it is possible to search for included objects within the multiobject field.

You can use a simple like statement as condition:

Code: Alles auswählen

<?php
$iObjectID = 0;
$sCondition = "(MultiobjectFieldname LIKE '%:\"".$iObjectID."\";%')"; ?>
<we:listview type="object" condition="$sCondition">
</we:listview>

Michael_S
Senior Member
Beiträge: 160
Registriert: Mi 4. Feb 2004, 02:39
Wohnort: London / UK
Kontaktdaten:

Re: Condition for Multi Object field

Beitragvon Michael_S » Mi 27. Mär 2013, 04:44

Hi Thomas,

Thanks for the code snippet but its not working for me, this is what I'm using for testing:

MultiobjectFieldname = Node_Category
Class field = Category_Name

Code: Alles auswählen

http://domain.com/index.php?cat=Gallery

<we:setVar to="global" nameto="iObjectID" from="request" namefrom="cat" />

<?php $sCondition = "(Node_Category LIKE '%:\"".$iObjectID."\";%')"; ?>

<we:listview type="object" condition="$sCondition"></we:listview>
Production Area
London, UK
http://productionarea.com

Michael_S
Senior Member
Beiträge: 160
Registriert: Mi 4. Feb 2004, 02:39
Wohnort: London / UK
Kontaktdaten:

Re: Condition for Multi Object field

Beitragvon Michael_S » Sa 29. Mär 2014, 13:15

Hi Thomas,

I'm using the code below which you suggested on a new project and its working well. However I'm wondering if there could be a situation where the statement could return unwanted results.

Would a LIKE statement comparing the Object ID '214' return '214' and '2140' for instance?

I've tried changing the statement to check for TRUE (===), equal to and of the same type (string) but without success.
ThomasGoebe hat geschrieben:Hi Michael,

it is possible to search for included objects within the multiobject field.

You can use a simple like statement as condition:

Code: Alles auswählen

<?php
$iObjectID = 0;
$sCondition = "(MultiobjectFieldname LIKE '%:\"".$iObjectID."\";%')"; ?>
<we:listview type="object" condition="$sCondition">
</we:listview>
Regards,

Michael.
Production Area
London, UK
http://productionarea.com

ThomasGoebe

Re: Condition for Multi Object field

Beitragvon ThomasGoebe » Sa 29. Mär 2014, 14:29

Hi Michael,

i think, it is a safe solution because the like statement searches for

:"214";
so :"2140"; does not match.

We discuss new solutions to store multiobjects in the database without serializing them. That will be failsafe, but will not be ready this year.

Michael_S
Senior Member
Beiträge: 160
Registriert: Mi 4. Feb 2004, 02:39
Wohnort: London / UK
Kontaktdaten:

Re: Condition for Multi Object field

Beitragvon Michael_S » Sa 29. Mär 2014, 17:42

Hi Thomas,

Thanks for the swift reply thats excellent news about the roadmap for the MultiObjects. I look forward to the update and you have reminded me to make a donation to the project to help make these things happen.

Regards,

Michael.
Production Area
London, UK
http://productionarea.com


Zurück zu „DB / Object Module“

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 2 Gäste