Code-quality Aggregate GetById default max 1 record
1432
Views
28
Comments
On our RadarOn our Radar
Aggregates & Queries

When creating an aggregate with the PK, please set the Max Records default to 1. 

May sound a bit trivial, and this is just an idea from a code-quality point of view :-) making the developer aware that the property Max records need to have a value. Otherwise you might run into an Unlimited Result-set impacting your application in a negative way.

The problem is, when someone then edits that query in a way where it SHOULD return multiple results... and then they don't know/remember to change it... it still works that way.

I think maybe the best way to do this is for the optimizer to silently add it if:

* There are no filter conditions other than the ID

* There is only one Source

If it was done like this, rather than by just automatically setting "Max Records", this would be a great change.

J.Ja

Changed the category to
Aggregates & Queries

Agree, it would be good feature to have.

2016-04-22 00-29-45
Nuno Reis
 
MVP
Merged this idea with 'Set Max. Records to 1 when' (created on 14 Jan 2020 13:59:11 by Beatriz Silva)

When developer implements a query "By Id" using Scaffolding it would be useful for performance and best practices matters to automatically set the Max. Records property to 1.



This comment was:
- originally posted on idea 'Set Max. Records to 1 when' (created on 14 Jan 2020 by Beatriz Silva)
- merged to idea 'Code-quality Aggregate GetById default max 1 record' on 05 Feb 2020 10:09:33 by Nuno Reis

Excellent idea Beatriz! +1



This comment was:
- originally posted on idea 'Set Max. Records to 1 when' (created on 14 Jan 2020 by Beatriz Silva)
- merged to idea 'Code-quality Aggregate GetById default max 1 record' on 05 Feb 2020 10:09:33 by Nuno Reis
Changed the category to
Aggregates & Queries


This comment was:
- originally posted on idea 'Set Max. Records to 1 when' (created on 14 Jan 2020 by Beatriz Silva)
- merged to idea 'Code-quality Aggregate GetById default max 1 record' on 05 Feb 2020 10:09:33 by Nuno Reis

Can be merge with older simular idea: https://www.outsystems.com/ideas/6582/code-quality-aggregate-getbyid-default-max-1-record?IsFromAdvancedSearch=True

It's worthwhile reading this idea as Justin James has some good observation on how it could better be implemented.



This comment was:
- originally posted on idea 'Set Max. Records to 1 when' (created on 14 Jan 2020 by Beatriz Silva)
- merged to idea 'Code-quality Aggregate GetById default max 1 record' on 05 Feb 2020 10:09:33 by Nuno Reis

. Very interesting! .



This comment was:
- originally posted on idea 'Set Max. Records to 1 when' (created on 14 Jan 2020 by Beatriz Silva)
- merged to idea 'Code-quality Aggregate GetById default max 1 record' on 05 Feb 2020 10:09:33 by Nuno Reis

Simple but effective



This comment was:
- originally posted on idea 'Set Max. Records to 1 when' (created on 14 Jan 2020 by Beatriz Silva)
- merged to idea 'Code-quality Aggregate GetById default max 1 record' on 05 Feb 2020 10:09:33 by Nuno Reis

As Daniël pointed a similar idea exists already, Let's combine these to get more votes.





This comment was:
- originally posted on idea 'Set Max. Records to 1 when' (created on 14 Jan 2020 by Beatriz Silva)
- merged to idea 'Code-quality Aggregate GetById default max 1 record' on 05 Feb 2020 10:09:33 by Nuno Reis

Also when Max Records is 1 then it doesn't make sense to have sorting on any column.



This comment was:
- originally posted on idea 'Set Max. Records to 1 when' (created on 14 Jan 2020 by Beatriz Silva)
- merged to idea 'Code-quality Aggregate GetById default max 1 record' on 05 Feb 2020 10:09:33 by Nuno Reis
2016-04-22 00-29-45
Nuno Reis
 
MVP

If we are talking of scaffolding, I agree with both MaxRecords=1 and no Order By Section.


If it is for any ById I disagree because you can select on the Detail Entity by HeaderId and if MaxRecords is 1 by default, it can be forgotten and some results will be missed.



This comment was:
- originally posted on idea 'Set Max. Records to 1 when' (created on 14 Jan 2020 by Beatriz Silva)
- merged to idea 'Code-quality Aggregate GetById default max 1 record' on 05 Feb 2020 10:09:33 by Nuno Reis

I get it, but I don't think it's intuitive that the Name field will affect a property in such a strong way.

I'd rather have queries with ById sufix have the Max Records property be mandatory and empty in this case, so that the dev's attention will be drawn to the error in red and a 1 or any number can be appropriately set.



This comment was:
- originally posted on idea 'Set Max. Records to 1 when' (created on 14 Jan 2020 by Beatriz Silva)
- merged to idea 'Code-quality Aggregate GetById default max 1 record' on 05 Feb 2020 10:09:33 by Nuno Reis
2016-04-22 00-29-45
Nuno Reis
 
MVP

Not by name Filipe. By name is error prone. By scaffolding.



This comment was:
- originally posted on idea 'Set Max. Records to 1 when' (created on 14 Jan 2020 by Beatriz Silva)
- merged to idea 'Code-quality Aggregate GetById default max 1 record' on 05 Feb 2020 10:09:33 by Nuno Reis

Should have red it more carefully, you are right Nuno.

thanks



This comment was:
- originally posted on idea 'Set Max. Records to 1 when' (created on 14 Jan 2020 by Beatriz Silva)
- merged to idea 'Code-quality Aggregate GetById default max 1 record' on 05 Feb 2020 10:09:34 by Nuno Reis

Please explain how this is different from the GetX function.
IE GetUser(ID)->Record



This comment was:
- originally posted on idea 'Set Max. Records to 1 when' (created on 14 Jan 2020 by Beatriz Silva)
- merged to idea 'Code-quality Aggregate GetById default max 1 record' on 05 Feb 2020 10:09:34 by Nuno Reis
2016-04-22 00-29-45
Nuno Reis
 
MVP

It is the same John, but when you drag Id to an Action, an aggregate by id is created, not a Get. William/Beatriz 's idea is to optimize such query.


Daniel, thanks for the heads up. The ideas combined have over 40 votes!

Good idea, agreed.

2014-02-07 17-02-43
Vasco Pessanha
Merged this idea with 'Aggregate with Max Records = 1 when creating it by dragging an identifier variable' (created on 17 Dec 2020 22:38:37 by Caio Santana Magalhães)

When you drag-and-drop a variable that has an identifier type onto the logic, it automatically creates an Aggregate filtering it by its Primary Key column.



That's really nice, but the Max Records value comes empty.



Since it's good practice, and it's actually one of the recommendations issued by Architecture Dashboard, it would be a good idea to have this set to 1.



This comment was:
- originally posted on idea 'Aggregate with Max Records = 1 when creating it by dragging an identifier variable' (created on 17 Dec 2020 by Caio Santana Magalhães)
- merged to idea 'Code-quality Aggregate GetById default max 1 record' on 18 Dec 2020 11:58:18 by Vasco Pessanha

GMTA ;)


https://www.outsystems.com/ideas/6582/code-quality-aggregate-getbyid-default-max-1-record



This comment was:
- originally posted on idea 'Aggregate with Max Records = 1 when creating it by dragging an identifier variable' (created on 17 Dec 2020 by Caio Santana Magalhães)
- merged to idea 'Code-quality Aggregate GetById default max 1 record' on 18 Dec 2020 11:58:18 by Vasco Pessanha
2014-02-07 17-02-43
Vasco Pessanha
Changed the status to
On our RadarOn our radar

Hi William,

Thanks a lot for the idea!

It's a good idea if there isn't joins.

Merged this idea with 'Max Record Value should automatically be filled with 1 when we know only 1 record will be fetched' (created on 07 May 2022 04:31:57 by Shubham Tiwari)

Max Record value of the aggregate when we filter by identifiers we know  that only one record will be fetched. This thing should be automated.

It will in turn give no errors on Architecture Dashboard also which in turn will fasten our development as well

I agree with you. In this case, Max Record should be by default 1. But can be changed by the user.

Regards

yes Thanks Alberto