Skip to Content

Flexible search query to fetch all existing Medias from a Media Container

I want to fetch all media present in media container using a flexible search query. I tried with this query

select {} from {Media AS M JOIN MediaContainer2MediaRel AS REL ON {}={M.PK} JOIN MediaContainer as MC ON {REL.source}={MC.PK}} WHERE {MC.qualifier} like '%OHTHH1_plp_container%'

I ended up with this error

Exception message : cannot search unknown field 'TableField(name='target',langPK='null',type=MediaContainer2MediaRel)' within type MediaContainer2MediaRel unless you disable checking , infoMap=TypeInfoMap for type = 8796093448274 code = MediaContainer2MediaRel superType = 8796093055058 itemTable = null ....

Please provide a solution for how to query to fetch all medias present in a media container.

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on Jul 15, 2020 at 11:46 AM


    You don't need to include the relation itself in the JOIN. You may try the other way round:

    SELECT {m:pk} 
    FROM {Media AS m JOIN MediaContainer AS mc ON {m:mediaContainer} = {mc:pk}} 
    WHERE {mc:qualifier} LIKE '%OHTHH1_plp_container%'

    If you have Media sub-types which are in separate tables, you may need to create a query per each sub-type and then make a union of the results.

    Best regards,


    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 14, 2020 at 03:55 PM

    It seems MediaContainer.medias is unsearchable. So, you can't do FlexSearch on it.

    An alternative would be to export it instead. This might help:

    INSERT_UPDATE MediaContainer;catalogVersion(catalog(id),version)[unique=true];qualifier[unique=true];medias(code)
    "#% impex.exportItemsFlexibleSearch(""SELECT {pk} FROM {MediaContainer AS mc} WHERE {mc.qualifier}='QUALIFIER'"");"

    Let me know if the answer helped you. If it does, don't forget to upvote and accept the answer.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Chang,

      Thanks for the answer. I want to export Media and its attributes by fetching all Medias present in a MediaContainer.

      There is a one to many relation existing in MediaContainer2MediaRel where source is 'MediaContainer' and target is 'Media'. so i was using this relation.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.