简体   繁体   English

Typo3 Typoscript-Select在以下情况下使用OR运算符

[英]Typo3 Typoscript-Select use OR-operator in where condition

I try select all Files from table sys_files which are linked with a category or the subcategories. 我尝试从与类别或子类别链接的表sys_files中选择所有文件。

On my Example the main category for files has the ID 1 and there are some sub-categories on it. 在我的示例中,文件的主要类别的ID为1,上面有一些子类别。

I first created the SQL-Code, to try it out directly on the database: 我首先创建了SQL代码,然后直接在数据库中进行尝试:

SELECT sys_file.name, sys_file.identifier, sys_category.title 
FROM sys_category 
RIGHT JOIN sys_file_metadata ON (sys_file_metadata.categories = 
sys_category.uid) 
JOIN sys_file ON (sys_file.uid = sys_file_metadata.file) 
WHERE (sys_category.parent = 1) OR (sys_category.uid = 1) 
order By sys_category.title

This works fine as expected. 这按预期工作正常。

Now, I tried to do it similar in typoscript, this looks like: 现在,我尝试在打字稿中执行类似的操作,如下所示:

lib.documentindex = CONTENT
lib.documentindex {
  wrap = <ul>|</ul>

  table = sys_category
  select {
    selectFields = sys_file.name, sys_file.identifier, sys_category.title
    rightjoin = sys_file_metadata ON (sys_file_metadata.categories = sys_category.uid) join sys_file ON (sys_file.uid = sys_file_metadata.file)
    where = sys_category.uid = 1 OR sys_category.parent = 1
    orderBy = sys_category.title
  }

  renderObj = COA
  renderObj.wrap = <li>|</li>
  renderObj.10 = TEXT
  renderObj.10 {
    field = identifier
    wrap = <a href="|">
  }
  renderObj.20 = TEXT
  renderObj.20.field = name
  renderObj.30 = TEXT
  renderObj.30.value = </a>

}

And this dosen't work. 而且这行不通。 But really strange is, it works halfway. 但真正奇怪的是,它只能成功一半。 So if i write the where like this: 所以,如果我这样写:

where = sys_category.uid = 1 OR sys_category.parent = 1

It displays as all files with a category on which the parent is 1. But it dosen't display files with the category where the id is 1. 它显示为父类别为1的所有文件。但不显示ID为1的类别的文件。

Do I now write it like 我现在写得像吗

where = sys_category.parent = 1 OR sys_category.uid = 1

It works the other way around, it displays files with the category where the id is 1. But none where the parent id is 1. 它以相反的方式工作,它显示的ID为1的类别的文件,但显示父ID为1的类别的文件。

In the official documentation of the select (found here ), it just tells on the where-option: 在select的官方文档(可在此处找到)中,它仅说明了where-option:

WHERE clause without the word "WHERE". WHERE子句,不含单词“ WHERE”。

But this is not all. 但这并不是全部。 I tried so much things and pretty everything i tried don't behave like real SQL code. 我尝试了很多事情,并且几乎所有尝试的行为都不像真正的SQL代码。 I don't know if this typo3-thing is buggy as hell or if I just use it totally wrong. 我不知道这种错别字是不是像地狱般的越野车,还是我完全错误地使用它。

I think your query is wrong (even the pure SQL). 我认为您的查询是错误的(甚至是纯SQL)。
categories are never(?) referenced immediately, but always with the mm-records in sys_category_record_mm . 类别从不立即引用(?),但始终与sys_category_record_mm的mm记录一起sys_category_record_mm
So your join needs to be another one where you join sys_category with sys_file via these mm-records (and the sys_file_metadata records): 因此,您的sys_category需要是另一sys_category ,您sys_file通过以下mm记录(和sys_file_metadata记录)将sys_file_metadatasys_file_metadata

SELECT sys_file.name, sys_file.identifier, sys_category.title
FROM sys_category
JOIN sys_category_record_mm 
  ON sys_category_record_mm.uid_local = sys_category.uid
JOIN sys_file_metadata 
  ON sys_file_metadata.uid = sys_category_record_mm.uid_foreign
JOIN sys_file 
  ON sys_file_metadata.file = sys_file.uid
WHERE sys_category_record_mm.tablenames = "sys_file_metadata" 
  AND sys_category_record_mm.fieldname = "categories"
  AND ((sys_category.parent = 1) OR (sys_category.uid = 1)) 
ORDER By sys_category.title

be aware: there are category fields in categorized records, but those only hold a counter of the references (given by the mm-records). 请注意:分类记录中有类别字段,但这些字段仅包含引用的计数器(由mm记录提供)。 It is not the uid of a category. 它不是类别的uid。
Might be misleading if you use the category with uid = 1 much often. 如果您经常使用uid = 1的类别,可能会产生误导。

Here is the typoscript realizing this Query: 这是实现此查询的文字:

Edit: Included TypoScript (by FuFu) This typoscript-select worked for me, but I had to move categories out of the root to the first page. 编辑:包含TypoScript(由 FuFu编写此错字选择对我有用,但我必须将类别从根目录移到第一页。

lib.documentindex = CONTENT
lib.documentindex {
  wrap = <ul>|</ul>

  table = sys_category
  select {
    pidInList = 1
    recursive = 1000
    selectFields = sys_file.name, sys_file.identifier, sys_category.title
    join = sys_category_record_mm ON (sys_category_record_mm.uid_local = sys_category.uid) JOIN sys_file_metadata ON (sys_file_metadata.uid = sys_category_record_mm.uid_foreign) JOIN sys_file ON (sys_file_metadata.file = sys_file.uid)
    where = (sys_category_record_mm.tablenames = "sys_file_metadata") AND (sys_category_record_mm.fieldname = "categories") AND ((sys_category.parent = 1) OR (sys_category.uid = 1))
    orderBy = sys_category.title
  }

  renderObj = COA
  renderObj.wrap = <li>|</li>
  renderObj.10 = TEXT
  renderObj.10 {
    field = identifier
    wrap = <a href="|">
  }
  renderObj.20 = TEXT
  renderObj.20.field = name
  renderObj.30 = TEXT
  renderObj.30.value = </a>

}

As

Did you try it with DataProcessing? 您是否尝试过DataProcessing? You can combine two DatabaseQueryProcessors to get what you need. 您可以结合使用两个DatabaseQueryProcessor来获得所需的内容。 See: https://docs.typo3.org/typo3cms/TyposcriptReference/7.6/ContentObjects/Fluidtemplate/Index.html#dataprocessing 参见: https : //docs.typo3.org/typo3cms/TyposcriptReference/7.6/ContentObjects/Fluidtemplate/Index.html#dataprocessing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM