Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicated custom fields in content component #24361

Closed
artur-stepien opened this issue Mar 26, 2019 · 10 comments

Comments

Projects
None yet
6 participants
@artur-stepien
Copy link
Contributor

commented Mar 26, 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.

@alikon

This comment has been minimized.

Copy link
Contributor

commented Apr 5, 2019

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

@ggppdk

This comment has been minimized.

Copy link
Contributor

commented Apr 5, 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

@alikon

This comment has been minimized.

Copy link
Contributor

commented Apr 5, 2019

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

@Bakual

This comment has been minimized.

Copy link
Contributor

commented Apr 5, 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.

@artur-stepien

This comment has been minimized.

Copy link
Contributor Author

commented Apr 5, 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?

@Bakual

This comment has been minimized.

Copy link
Contributor

commented Apr 6, 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 😄

@alikon

This comment has been minimized.

Copy link
Contributor

commented Apr 6, 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 ?

@franz-wohlkoenig

This comment has been minimized.

Copy link
Member

commented Apr 6, 2019

closed as having a Pull Request.

@artur-stepien

This comment has been minimized.

Copy link
Contributor Author

commented Apr 8, 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.

@alikon

This comment has been minimized.

Copy link
Contributor

commented Apr 8, 2019

@artur-stepien please test #24516

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.