Yii Framework Forum: Gii and Tbl_ Relations - Yii Framework Forum

Jump to content

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

Gii and Tbl_ Relations Rate Topic: -----

#1 User is offline   jdwolff 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 26-January 11

Posted 29 January 2011 - 08:38 AM

Hello,

I'm putting myself through the beginning paces with Yii. I've noticed that Gii's been having some trouble defining model relations if my tables are prefixed with tbl_. I've three tables, tbl_project, tbl_user and a join table, tbl_project_user_assignment.

When I generate the crud for tbl_project it defines the relationship with tbl_user as tblUser, not user. If I drop the tbl_ prefix everything works fine, so it's not a huge deal, but it does make me wonder if I'm doing something wrong.

Can anybody shed some light on this?

Thanks,
JW
0

#2 User is offline   Antonio Ramirez 

  • Elite Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 1,448
  • Joined: 04-October 10

Posted 29 January 2011 - 01:59 PM

Did you configured your config (main.php) file to have 'tbl_' prefix?

'db'=>array(
  // .....
  'tablePrefix' => 'tbl_', //<---
),

┬┐How long would it take for you to understand that you own nothing in this world?

www.ramirezcobos.com
www.2amigos.us
www.github.com/tonydspaniard
www.github.com/2amigos


Posted Image
0

#3 User is offline   Ali Borjian 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 358
  • Joined: 19-January 11

Posted 02 May 2011 - 04:19 AM

View PostAntonio Ramirez, on 29 January 2011 - 01:59 PM, said:

Did you configured your config (main.php) file to have 'tbl_' prefix?

'db'=>array(
  // .....
  'tablePrefix' => 'tbl_', //<---
),



It's the clue , I had such problem and when I added this code it solved!

0

#4 User is offline   qinsanep 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 04-October 11

Posted 30 December 2011 - 12:59 AM

View PostAntonio Ramirez, on 29 January 2011 - 01:59 PM, said:

Did you configured your config (main.php) file to have 'tbl_' prefix?

'db'=>array(
  // .....
  'tablePrefix' => 'tbl_', //<---
),





I have a similar problem.

I have created tables for my current project, without the tbl_ prefix.
But now i have installed the fbgallery extention which uses tbl_

When i run the page i get an error not being able to find the tables because they are looking for names tables without this prefix...

What would be the best solution when working with two different table naming standards ?

Thank you
0

#5 User is offline   qinsanep 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 04-October 11

Posted 31 December 2011 - 10:56 AM

Turns out that setting that prefix in my main, will not affect non prefixed tables, and everything works just fine. Im not sure how it works , but it does... Maybe someone could shed some light on this ?

Thanks
0

#6 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 31 December 2011 - 11:02 AM

Read more here.

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#7 User is offline   Hesam 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 12-November 12
  • Location:Toronto

Posted 11 December 2012 - 07:46 PM

View Postqinsanep, on 31 December 2011 - 10:56 AM, said:

Turns out that setting that prefix in my main, will not affect non prefixed tables, and everything works just fine. Im not sure how it works , but it does... Maybe someone could shed some light on this ?

Thanks


I get very similar error:
'tblDiscounts' => array(self::MANY_MANY, 'Discounts', '{{orders_discs}}(orders_id, discounts_id)'),


as you can see tbl_orders_discs is replace because I added prefix tbl_ to the main config, however I get anoying tblDiscounts as a veriable to define the relation.

Here is the top of my model:

* The followings are the available model relations:
 * @property Users $user
 * @property Files $file
 * @property Discounts[] $tblDiscounts



it seems that the problem rises when I have many to many relationship. Removing the tbl prefix from main config doesn't help. Also adding and removing tbl prefix in the Gii menu didn't help.
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