Yii Framework Forum: Gii and SQL Server - won't generate models if a column starts with a number - Yii Framework Forum

Jump to content

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

Gii and SQL Server - won't generate models if a column starts with a number Rate Topic: -----

#1 User is offline   vario 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 36
  • Joined: 03-January 10

Posted 28 September 2011 - 10:06 AM

Hi,

I'm working on a project that requires I use a legacy database - I have no control over the database structure at all, and can make no changes to it. I've successfully have the database connection working with Microsoft's SQLSRV driver, and can create most models fine.

There are tables where column names include numbers, and therefore, SQL Server requires you to put square brackets around the column name. The same thing can be done when you can create columns with spaces (why, I've no idea), so long as you add square brackets around it.

So the table structure may be as follows:

CREATE TABLE [dbo].[Genres](
    ID [int] IDENTITY(1,1) NOT NULL,
    [50s] [bit] NULL,
    [60s] [bit] NULL,
    [70s] [bit] NULL
)


However, in attempting to use Gii to generate a model for this table, I recieve the following error:

Column names that does not follow PHP variable naming convention: Genres.50s.


Is there any known solution to this? Like I say, I can't rename the columns.

Thanks in advance.
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 28 September 2011 - 04:55 PM

Yii uses PHP magic methods (http://php.net/manua....oop5.magic.php) so that there is no need to create all the variables for the fields of the database table

For example if in a table you have the field "name" in the model you can use $model->name without declaring a property "name"...

That is the reason why the table fields have to follow PHP variable naming convention...

So in your case I'm afraid there is no easy solution... you will miss all the automatic functionality... you would need to create manually the model attributes... but even the commands for retrieving and saving them to proper fields...
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   MegaCore 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 16-January 12

Posted 04 April 2014 - 08:16 AM

View Postvario, on 28 September 2011 - 10:06 AM, said:

Hi,

I'm working on a project that requires I use a legacy database - I have no control over the database structure at all, and can make no changes to it. I've successfully have the database connection working with Microsoft's SQLSRV driver, and can create most models fine.

There are tables where column names include numbers, and therefore, SQL Server requires you to put square brackets around the column name. The same thing can be done when you can create columns with spaces (why, I've no idea), so long as you add square brackets around it.

So the table structure may be as follows:

CREATE TABLE [dbo].[Genres](
    ID [int] IDENTITY(1,1) NOT NULL,
    [50s] [bit] NULL,
    [60s] [bit] NULL,
    [70s] [bit] NULL
)


However, in attempting to use Gii to generate a model for this table, I recieve the following error:

Column names that does not follow PHP variable naming convention: Genres.50s.


Is there any known solution to this? Like I say, I can't rename the columns.

Thanks in advance.


I know this is coming more than a tad late but I only just came across this yesterday. What you could do is create views from the erring tables and then create your models from those views.
0

#4 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 508
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 04 April 2014 - 11:32 AM

That's right but beyond that you must take care of the following as per this post.
José
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