No Relations Defined In Model

I have an Oracle database with various tables. I’ve tried creating a model based on one of my tables and although the model is successfully created, no relations are defined even though there are foreign key constraints defined in the database for the target table. Any ideas why the constraints would not be picked up by the Gii model generator?

There are no table prefixes and I’m using the oci8Pdo extension in my project.

Thanks in advance!

Wow, sorry to reply nearly a month late, but maybe it can help others with the same problem.

I encountered this issue with Oracle XE 11gr2 because I was using gii on tables in a schema other than the default. See this issue:

https://github.com/resurtm/yii/commit/d786dd3b1cfc58976e17b78f8e74dc1d949c8cf0

In my case, this issue was (mostly) by that patch. It’s not a perfect fit, however, as I get relations() like this:




/**

     * @return array relational rules.

     */

    public function relations()

    {

        // NOTE: you may need to adjust the relation name and the related

        // class name for the relations automatically generated below.

        return array(

            'tRANSITIONs' => array(self::HAS_MANY, 'TRANSITION', 'FROM_STATE_ID'),

            'tRANSITIONs1' => array(self::HAS_MANY, 'TRANSITION', 'TO_STATE_ID'),

            'sUBSCRIPTIONs' => array(self::HAS_MANY, 'SUBSCRIPTION', 'FROM_STATE_ID'),

            'sUBSCRIPTIONs1' => array(self::HAS_MANY, 'SUBSCRIPTION', 'TO_STATE_ID'),

            'wORKFLOW' => array(self::BELONGS_TO, 'WORKFLOW', 'WORKFLOW_ID'),

            'hISTORies' => array(self::HAS_MANY, 'HISTORY', 'FROM_STATE_ID'),

            'hISTORies1' => array(self::HAS_MANY, 'HISTORY', 'TO_STATE_ID'),

        );

    }



Unfortunately, I haven’t been able to resolve case-sensitivity issues with gii and Oracle. The unhappy compromise we’ve settled on has been upper-case column names and Camel-case model names (which sometimes we have to correct by hand).

Some more information: turning on the CWebLogRoute can be invaluable in debugging these issues (protected/config/main.php):




  'components' => array(

   ...

    'log' => array(

    ...

      'routes' => array(

      ...

        // uncomment the following to show log messages on web pages

        array(

          'class'=>'CWebLogRoute',

        ),

      )

    )



Here I noticed it was correctly querying columns and relations for the schema in which the table I was generating resided, but eventually it queried relations in the default schema. It turns out the validation methods for this form were correctly using the schema to do validation, but the code generator itself wasn’t.