J3 Issue ?
avatar artur-stepien
artur-stepien
26 Mar 2019

Steps to reproduce the issue

  • Go to administration of Content component
  • Create a category called A
  • Create a category called B and select parent category to A so the category tree looks like this: A -> B
  • Create custom article field called Test and as a category select both A and B. Then in Options tab select Automatic Display to Before Content
  • Create article called Test Article in B category and fill Test field with with: This is the test field
  • Create a new articles blog view menu item displaying articles from B category
  • Go to front end and open the new menu item you created
  • Find the article called Test Article and open it.

Expected result

This article Test field should only be visible once

Actual result

Field is duplicated

System information (as much as possible)

3.9.4 but I'm pretty sure it goes back to the introduction of custom fields

Additional comments

I investigated the matter and it is caused by incomplete query in FieldsModelFields model (method getListQuery) from /administrator/components/com_fields. There is no group by in the query so field will be duplicated as many times as the number of parent categories on which your custom field exists. So if your tree is like A -> B -> C -> D and you place the article in D with setting the custom field to be available in all 4 categories you will have this field displayed 4 times. Simple group by should do the trick. It exists in content component but I'm pretty sure it affects all components using custom form fields and categories.

avatar artur-stepien artur-stepien - open - 26 Mar 2019
avatar joomla-cms-bot joomla-cms-bot - labeled - 26 Mar 2019
avatar franz-wohlkoenig franz-wohlkoenig - change - 27 Mar 2019
Status New Discussion
avatar artur-stepien artur-stepien - change - 27 Mar 2019
The description was changed
avatar artur-stepien artur-stepien - edited - 27 Mar 2019
avatar franz-wohlkoenig franz-wohlkoenig - change - 4 Apr 2019
Labels Added: J3 Issue
avatar franz-wohlkoenig franz-wohlkoenig - labeled - 4 Apr 2019
avatar alikon
alikon - comment - 5 Apr 2019

i'm unable to replicate if i understand this issue correctly
Screenshot from 2019-04-05 18-40-46

avatar ggppdk
ggppdk - comment - 5 Apr 2019

Confirmed, e.g. you have field assigned to category D

  • and you have category tree
    A
    -> B
    -> -> C
    -> -> -> D

If you also assign field to the (ancestor) categories A,B,C (see picture)

bug_field_mul_view

Then you will get field values to appear 4 times when viewing the article in category D because,
there is no group-by (or other solution) in the getListQuery() as the description says

https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_fields/models/fields.php#L219-L224

// Join over the assigned categories
$query->join('LEFT', $db->quoteName('#__fields_categories') . ' AS fc ON fc.field_id = a.id')

results in joining with the __fields_categories table 4 times, and getting same field 4 times

avatar alikon
alikon - comment - 5 Apr 2019

yes i can confirm the issue now
thanks @ggppdk for info ?

avatar Bakual
Bakual - comment - 5 Apr 2019

I would look for another solution than using group-by. Groups are meant to use aggregate functions on the grouped rows. We don't need that.
A better approach is using DISTINCT.

avatar artur-stepien
artur-stepien - comment - 5 Apr 2019

Well in this situation GROUP BY or DISTINCT makes no difference. Its just internal way of finding fields. So Just use the faster one?

avatar Bakual
Bakual - comment - 6 Apr 2019

GROUP BY also means you need to add each selected column (that doesn't contain different values) to the GROUP BY command.
DISTINCT is much simpler as you can just specify one column.

So at least the code gets simpler with DISTINCT ?

avatar alikon
alikon - comment - 6 Apr 2019

for me the issue is here https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_fields/models/fields.php#L209
why
// Traverse the tree up to get all the fields which are attached to a parent ?

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 6 Apr 2019

closed as having a Pull Request.

avatar franz-wohlkoenig franz-wohlkoenig - change - 6 Apr 2019
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2019-04-06 07:25:27
Closed_By franz-wohlkoenig
avatar franz-wohlkoenig franz-wohlkoenig - close - 6 Apr 2019
avatar artur-stepien
artur-stepien - comment - 8 Apr 2019

@alikon The inheritance is ok. With 150+ children for lets say a products catalogue you don't have to add every category. If you have 10 fields that should be in 150 categories you're basically f*** :D So the inheritance is ok.

avatar alikon
alikon - comment - 8 Apr 2019

@artur-stepien please test #24516

Add a Comment

Login with GitHub to post a comment