yii2-gii icon indicating copy to clipboard operation
yii2-gii copied to clipboard

active relations not generated in PostgreSQL database

Open yii-bot opened this issue 6 years ago • 9 comments

This issue has originally been reported by @tepaleguiojo at https://github.com/yiisoft/yii2/issues/15823. Moved here by @SilverFire.


What steps will reproduce the problem?

  1. create migration for user schema
  2. create migration for table user.account
  3. create migration for table user.profile with foreign key to user.account
  4. run php yii gii/model --tableName=user.* --ns="app\modules\user\models" --baseClass="app\components\ActiveRecord"

What is the expected result?

Relation method/s like getUserAccount() or getAccount(), depends on what the gii will produce, functions to be used in with() and joinWith()

What do you get instead?

No relations method created. Only rules() and attributeLabels() methods in model class are generated.

Additional info

Q A
Yii version 2.0.14.1
PHP version 7.1.9
Operating system Windows 7 Ultimate 64 Bit
PostgreSQL Version 10.1, compiled by Visual C++ build 1800, 64-bit

yii-bot avatar Mar 02 '18 16:03 yii-bot

Такая же проблема. Исправьте, пожалуйста =) В файле \generators\model\default\model.php переменная $relations содержит пустой массив. Gii version: 2.1.0 Yii version: 2.0.19

sokollondon avatar Jul 31 '19 07:07 sokollondon

@sokollondon можете сделать дамп схемы? Если генерируете не из консоли, а из веб-интерфейса, всё нормально?

samdark avatar Jul 31 '19 08:07 samdark

@samdark генерирую из веб-интерфейса. Дамп тут https://yadi.sk/d/tsWhBdKMEe1bKA для примера пытался сгенерировать модель таблицы planning.invoices, должен быть relation getContracts

sokollondon avatar Jul 31 '19 09:07 sokollondon

Solved the problem by unchecking the Generate Relations from Current Schema In general, if you check the box, then the relation is displayed only from the public schema, although the current schema is different. But for me it doesn't matter, I made the checkbox unchecked by default in the gii config 'generateRelationsFromCurrentSchema' => false, let all be displayed =)

sokollondon avatar Sep 12 '19 09:09 sokollondon

@sokollondon do you have public as default schema for the connection?

samdark avatar Sep 12 '19 09:09 samdark

@samdark Yes

sokollondon avatar Sep 12 '19 10:09 sokollondon

OK. Cross-schema relations aren't detected.

samdark avatar Sep 12 '19 14:09 samdark

@samdark @sokollondon

Hi, whether the issue solved? I got same issue.

Thanks

haifahrul avatar Aug 08 '20 19:08 haifahrul

It is not. Noone is working on it at the moment. If you want to, feel free to take it.

samdark avatar Aug 09 '20 10:08 samdark