Fixing misspelled table names from previous developer, changing table names prefixes, configurable table names for Symfony plugins, easier to grep/search/replace, etc. Not many reasons but it is still a good practice. There is always reason to go against Abstraction when you writing code because it is 'extra' work ... it is mostly appreciated by the next guy reading/using it.
To make things more readable (if I have to write a query instead of using Criteria object), I usually do something like: $tbl_user = UserPeer::TABLE_NAME; $sql_string = "SELECT * FROM $tbl_user"; (of course the above should be written with Criteria object, but just to illustrate) On Thu, Mar 26, 2009 at 8:19 PM, Benjamin <[email protected]> wrote: > > This question may be unrelated to symfony, and more related to > database abstraction, but I'm wondering why I should pull the table > names from the model. I've been programming for a long time and have > never seen anyone need to use dyamic table names except when they have > prefixes on them that can change. > > So, this is a pain to type out: > > public static function getUserLabelsWithPasswordCounts($userId) { > $query = "SELECT > " . PasswordLabelPeer::NAME . ", > (SELECT COUNT(*) FROM " . > PasswordLabelPasswordsPeer::TABLE_NAME . " WHERE " . > PasswordLabelPasswordsPeer::LABEL_ID . " = " . PasswordLabelPeer::ID . > ") AS pcount > FROM > " . PasswordLabelPeer::TABLE_NAME . " > WHERE > " . PasswordLabelPeer::ID . " = '$userId' > ORDER BY > " . PasswordLabelPeer::NAME . " ASC"; > > $con = Propel::getConnection(); > $pdo = $con->prepare($query); > $pdo->execute(); > > return $pdo->fetchAll(PDO::FETCH_OBJ); > } > > > -- Blue Horn Ltd - System Development http://bluehorn.co.nz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~----------~----~----~----~------~----~------~--~---
