richard.herbert
08/08/2022, 8:53 AMquick
trying to be too clever?
• I have a table called smartmeters
• I have an entity called SmartMeter.cfc
• I am using the QuickService
• I have property name="SmartMeterService" inject="quickService:SmartMeter"
in my handler's pseudo constructor
• I'm calling var smartMeters = SmartMeterService.all()
• And bang Table 'smart_meters' doesn't exist
• WHAT?
So it seems like quick
said...
Oooh, oooh, I can make two words out of "smartmeters" so I'll be helpful and snake case it for you even though your entity name actually matches exactly an existing table name, do you like what I did there!
No thank you!
I shouldn't really have to component _table_='smartmeters' ...
my entity when there's already an exact match with a table, surely?wil-shiftinsert
08/08/2022, 10:13 AMWe don’t need to tell Quick what table name to use for our entity. By default, Quick uses the pluralized name of the component for the table name. That means for ourentity Quick will assume the table name isUser
. You can override this by specifying ausers
metadata attribute on the component.table
wil-shiftinsert
08/08/2022, 10:17 AMsmart_meters
. Maybe you have a type in some unexpected location, although I can’t imagine.
• specify the exact tablename to see if this fixes the problem. Don’t forget to reload coldbox, some of the quick metadata is cached. If that fixes the problem the automatic naming is incorrect, but again: not sure about thatwil-shiftinsert
08/08/2022, 10:19 AMparam meta.originalMetadata.table = variables._str.plural( variables._str.snake( meta.entityName ) );
Yes, indeed. Now I am convinced I am never going to use this automatic naming. It is in the BaseEntity within the metaDataInspection function and not documented in the manual. It has been there since v 1.0richard.herbert
08/08/2022, 10:25 AMrichard.herbert
08/08/2022, 10:26 AMwil-shiftinsert
08/08/2022, 10:32 AMrichard.herbert
08/08/2022, 10:35 AMwil-shiftinsert
08/08/2022, 11:13 AMrichard.herbert
08/08/2022, 11:33 AMbdw429s
08/08/2022, 3:32 PMI'm struggling to imagine the conversationI'm not-- I'm sure the conversation happened in the context of a DB where the naming convention was snake case and the CFC naming convention was not 🤷 It probably seemed pretty useful at the time with the obvious work around that you could override the table name if you didn't like the default. Perhaps @elpete can just add a setting to disable the snake case assumption in automatic naming. I have yet to see two clients using the exact same DB naming conventions, so Eric is sort of darned if he does and darned if he doesn't because nothing is going to match every use case.
richard.herbert
08/08/2022, 4:33 PMelpete
08/08/2022, 5:08 PMsnake_case
convention. I’m sorry it caused issues today, @richard.herbert. I was fairly certain it was in the docs already. In fact, I went to where I thought it was and read it and could hear “snake cased” in my head, but it definitely wasn’t there.
@bdw429s is right that database naming conventions are the part of Quick that everyone disagrees with. 😉 In particular, I think the snake_cased
table names are actually the last remnant from the early version of Quick where all columns were retrieved by default (you didn’t need to specify properties) and the relationship conventions also assumed snake_case
. The relationship conventions changed to just be camelCase
, but it looks like the table names stuck around.
Again, sorry for the missing docs that contributed to a frustrating experience.richard.herbert
08/08/2022, 5:27 PMtable
attribute as Wil said.
I think @wil-shiftinsert has submitted a doc's pr on the subject?elpete
08/08/2022, 5:58 PMwil-shiftinsert
08/08/2022, 8:04 PMelpete
08/08/2022, 8:07 PMelpete
08/08/2022, 8:07 PMwil-shiftinsert
08/08/2022, 8:10 PMdanmurphy
08/08/2022, 11:19 PMelpete
08/08/2022, 11:22 PMrichard.herbert
08/09/2022, 6:50 AM