cancel
Showing results for 
Search instead for 
Did you mean: 

What is the best practice in flexible search?

amigley_bastardo
Explorer
0 Kudos
673

Hi,

I have a doubt, later of an audit performed on my company. When I create a flexible search query in a DAO class, it is considered good practice to use aliases for types and attributes? Or, should I should refer directly to the name of the Type:

For example, should I do this?

 select {p.pk}, {p.name} from {Product as p}

Or, is this better?

 select {Product.pk}, {Product.name} from {Product}

regards!

Amy

Accepted Solutions (1)

Accepted Solutions (1)

former_member633554
Active Participant
0 Kudos

Alias is better because many types share the same attribute names and you'll get ambiguous column errors when doing joins. This is good.

select {p.pk}, {p.name} from {Product as p}

Answers (1)

Answers (1)

geffchang
Active Contributor
0 Kudos

I also agree with Leo's answer.

But if you have only Type, you don't need to use alias. This should be enough:

 SELECT {pk}, {name} FROM {Product}

If you join with other Types, an alias will be useful:

 SELECT 
     {p.code}, {cg.code}, {cat.id}, {catver.version} 
 FROM
     {Product AS p 
     JOIN CategoryProductRelation AS rel ON {p.PK} = {rel.target}
     JOIN Category AS cg ON {rel.source} = {cg.PK}
     JOIN CatalogVersion AS catver ON {catver.pk}={cg.catalogVersion}
     JOIN Catalog AS cat ON {cat.pk}={catver.catalog}
     }
 WHERE 
     {cat.id} LIKE 'Default' 
     AND {catver.version} LIKE 'Staged'

Other useful references: