Why do you use so much duplicate code?
And those are just some parts I looked at. I could probably write here another 90 examples..
When writing code you shouldn't repeat yourself (DRY). It seems like your main business is not programming. I don't want to teach you programming, but this code looks like it's written by some interns and you even sell this product.
The text was updated successfully, but these errors were encountered:
You are correct we could reference the
You will notice in most cases we are not using active record queries, and instead, write the query ourselves which we found is a performance improvement.
Personally, doing lots of string interpolation (to put the table name in) within a custom query string annoys me.
You are welcome to use the
In the future, we might change the convention, but for now, we would rather it be consistent.
Thanks for the feedback.
Mostly performance reasons. DB actions are localized in the service layer and table names are pretty unlikely to change, so introducing an overhead there just does not seem like the right move.
Product Record does not have actual properties you refer to (https://github.com/craftcms/commerce/blob/develop/src/records/Product.php#L17-L37), because it depends on the
As far as Product Element goes, those properties should be defined similar to how it's in the Product Record to avoid ambiguity, but even if that wasn't the case, not all properties for the Product should be queryable and stuffing this all under a trait unnecessary couples the product and it's query. Furthermore, the vast majority of the properties don't even have the same definition. The
'commerce_products' is a table alias there, as the actual table can have a prefix. (https://github.com/craftcms/cms/blob/develop/src/elements/db/ElementQuery.php#L1550-L1552)
Sticking to DRY is nice, but sometimes duplication is far cheaper than the wrong abstraction.