← Back to team overview

dhis2-devs team mailing list archive

Re: Ordering of category option names in the resource tables

 

Hi,

sorry for the late reply.


> It was later discovered, probably when making pivot table views for
> Excel would be my guess, that in fact a persisted name is quite handy
> - many times easier than doing the sql equivalent of what is is done
> in java to produce "(Male,<1)" (or "(<1,Male)" ).  So we created the
> _catoptcomboname table.


This is right. The names when used inside the application are generated on
the fly based on the category options and category combination. When
creating SQL reports, however, it is tricky to generate this (for anyone
except Jason that is;), so we decided to have a resource table for it. The
reason for not putting it on the categoryoptioncombo table is that this
table is generated by Hibernate and is part of the domain model - it is by
many people including me considered bad practice to tamper with entity
database tables. Having a separate table is cleaner and not really a
problem. One might also want to expand this with more information later.

The reason for the sort order flaw is a bit boring. The association between
category option and option combination is bi-directional. Category option -
> option combination is represented as a Java List, which is an ordered
collection. Option combination -> category option is represented as a Java
Set, which is an unordered collection. The reason for this is that
maintaining a bidirectional association with Lists in both ends does not
make sense - you might get conflicts when you have overlapping objects.

So for the resource table I can see we use the Set association from option
combination -> category option to render the names. We should ideally use
the association from the other end to maintain sort order. Will see if we
can fix this shortly.

regards,

Lars

Follow ups

References