28
Views
2
Comments
Solved
Best practice: Join with User entity, or use GetUser(), in TableRecords cells?
Question

Hi all,

Quick question: in circumstances in which you are displaying user data such as the user's name, username, and/or email in a TableRecord or other widget, is it best practice to join with the User table in the aggregate or SQL element bound to that widget, or to instead use the GetUser([Foreign Key Field]) method within the cell in question to fetch the user information for each row?

To me it seems to make more sense to just include a join with the User table in the aggregate, especially in cases where the User might be null (making sure to use a "With or Without" join), so you don't have to wrap the GetUser() function in an "If" statement to handle that case, but I've worked on lots of projects where the other technique was used.

Thanks!
Kirk

Rank: #170
Solution

Hi Kirk,

In almost every case to show data in table, is always more performance wise doing a Join.

As Leandro pointed each GetUserId() will make a call to your DB, increasing a lot the time to show data in your table.

If you want to format the items in the cell you can always use a web block receiving the fields you need avoiding, this way, doing a query in the webblock's preparation.


Take a look in the queries best practices specially in this one:

Cheers,

RR

mvp_badge
MVP
Rank: #156

Hi Kirk,

In my opinion, it's dependes of the data usage. 

But, with your description, in this case, use the join in the aggregate it's better.

Because the GetUser() function is a database transaction, so wich row will be a new database transaction.


Regards,

Leandro.

Rank: #170
Solution

Hi Kirk,

In almost every case to show data in table, is always more performance wise doing a Join.

As Leandro pointed each GetUserId() will make a call to your DB, increasing a lot the time to show data in your table.

If you want to format the items in the cell you can always use a web block receiving the fields you need avoiding, this way, doing a query in the webblock's preparation.


Take a look in the queries best practices specially in this one:

Cheers,

RR