Yii Framework Forum: Case Sensitive Model Attributes For Case Insensitive Db - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Case Sensitive Model Attributes For Case Insensitive Db Rate Topic: -----

#1 User is offline   davidgraybeard 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 13-December 12

Posted 28 June 2013 - 08:02 PM

I understand that Postgres is case insensitive with respect to column names. I've read the recommendation to use lower case attribute names, but I'd like the models to be able to use camel hump names and have Yii do the magic behind the scenes when dealing with the DB. For example, I'd like to reference $user->userName in the model, regardless of the DB implementation. It just makes for more readable code. (I don't want to use underscores, partly because I migrated from MySQL and have 66 tables with columns already named, along with lots of existing code.) Is there a setting somewhere that will allow me to do this?
0

#2 User is offline   davidgraybeard 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 13-December 12

Posted 28 June 2013 - 09:51 PM

I found an answer to my own question and hoping it may help others.

If you use double quotes when defining tables in Postgres the case sensitivity is preserved.

create table "FooBar" ("myColName" char);



This causes the model generator in Yii to generate nicely humped attribute names. Unfortunately, to reference those columns in SQL queries in Yii you then need to use the double quotes. That includes when specifying the column names for conditions. For example:

$condition = '"organizationId" = :orgId'

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users