Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gii for advanced template not creating relationship #299

Open
ashunigam opened this issue Sep 13, 2017 · 2 comments
Open

Gii for advanced template not creating relationship #299

ashunigam opened this issue Sep 13, 2017 · 2 comments
Labels
status:to be verified Needs to be reproduced and validated. type:bug Bug

Comments

@ashunigam
Copy link

ashunigam commented Sep 13, 2017

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 samdark added status:to be verified Needs to be reproduced and validated. type:bug Bug labels Sep 13, 2017
@samdark samdark added this to the 2.0.7 milestone Sep 13, 2017
@samdark
Copy link
Member

samdark commented Sep 13, 2017

Good report. Thanks.

@samdark samdark modified the milestones: 2.0.7, 2.0.8 Apr 30, 2018
@samdark samdark modified the milestones: 2.0.8, 2.1.1 Dec 8, 2018
@samdark samdark modified the milestones: 2.1.1, 2.1.2 Aug 13, 2019
@samdark samdark removed this from the 2.1.2 milestone Nov 19, 2019
@Chi-G
Copy link

Chi-G commented Jul 26, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:to be verified Needs to be reproduced and validated. type:bug Bug
Projects
None yet
Development

No branches or pull requests

3 participants