yiisoft / yii2-gii

Yii 2 Gii Extension
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
202 stars 192 forks source link

Gii for advanced template not creating relationship #299

Open ashunigam opened 7 years ago

ashunigam commented 7 years ago

What steps will reproduce the problem?

What's expected?

A relationship code as happens in the video

What do you get instead?

no relationship function created for department and branches.

Additional info

sql to create database: -- phpMyAdmin SQL Dump -- version 4.5.4.1deb2ubuntu2 -- http://www.phpmyadmin.net

-- Host: localhost -- Generation Time: Sep 13, 2017 at 10:20 AM -- Server version: 5.7.19-0ubuntu0.16.04.1 -- PHP Version: 7.0.22-0ubuntu0.16.04.1

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00";

/!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /; /!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /; /!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /; /!40101 SET NAMES utf8mb4 /;

-- -- Database: advanced_yii2

CREATE DATABASE IF NOT EXISTS advanced_yii2 DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci; USE advanced_yii2;


-- -- Table structure for table branches

CREATE TABLE IF NOT EXISTS branches ( branch_id int(11) NOT NULL AUTO_INCREMENT, companies_company_id int(11) NOT NULL, branch_name varchar(100) NOT NULL, branch_address varchar(255) NOT NULL, branch_created_date datetime NOT NULL, branch_status enum('active','inactive') NOT NULL, PRIMARY KEY (branch_id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- -- RELATIONS FOR TABLE branches: -- companies_company_id -- companies -> company_id


-- -- Table structure for table companies

CREATE TABLE IF NOT EXISTS companies ( company_id int(11) NOT NULL AUTO_INCREMENT, company_name varchar(100) NOT NULL, company_email varchar(100) NOT NULL, company_address varchar(255) NOT NULL, company_created_date datetime NOT NULL, company_status enum('active','inactive') NOT NULL, PRIMARY KEY (company_id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- -- RELATIONS FOR TABLE companies:


-- -- Table structure for table departments

CREATE TABLE IF NOT EXISTS departments ( department_id int(11) NOT NULL AUTO_INCREMENT, branches_branch_id int(11) NOT NULL, department_name varchar(100) NOT NULL, companies_company_id int(11) NOT NULL, department_created_date datetime NOT NULL, department_status enum('active','inactive') NOT NULL, PRIMARY KEY (department_id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- -- RELATIONS FOR TABLE departments: -- branches_branch_id -- branches -> branch_id -- companies_company_id -- companies -> company_id

/!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT /; /!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS /; /!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION /;

UPDATE

I used internal relation in place of foreign key in above case. Thats the reason in sql dump I am getting relation in commented form. So if internal relation is not supposed to be treated as foreign key then code is working as expected. Once I check it with foreign key, I will update the comment and close this ticket.

samdark commented 7 years ago

Good report. Thanks.

Chi-G commented 3 years ago

Kindly show how to write the script for RELATION BTW Branches and Departments table?

ALTER TABLE departments ADD FOREIGN KEY (branches_branch_id) REFERENCES advanced_yii2.branches (branch_id) ON DELETE RESTRICT ON UPDATE RESTRICT

I'm using the above script and it's throwing an SQL no database error