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

Update/View buttons broken if table/model has composite primary keys #14

Closed
realmarkcross opened this issue Aug 10, 2015 · 6 comments
Closed

Comments

@realmarkcross
Copy link

When creating a view using a model with a composite primary key, the composite key is not copied over to the 'Update' button on the View or Index pages which causes the buttons to break (with a composite key; because Yii is looking for the ID's of the composite keys too.

As a workaround:
If for example, your additional primary keys (besides id) are entity_id and label_id, the primary keys must be added to the 'update' button's code in the View file, like so:

$model['id'], **'entity_id' => $model['entity_id'], 'label_id' => $model['label_id'**]], ['class' => 'btn btn-primary']) ?>
@realmarkcross realmarkcross changed the title Composite key model generation doesn't update the Update/View buttons Update/View buttons broken if table/model has composite primary keys Aug 10, 2015
@mootensai
Copy link
Owner

can you provide your SQL?

@realmarkcross
Copy link
Author

This item should be reproducible by creating a table/model with a composite primary key and running the CRUD app. You will see that you can't update or delete a record until you manually put the rest of the composite key fields into the update/delete button's code as listed above.

@mootensai
Copy link
Owner

Whew.. could you help me to fix this?

@realmarkcross
Copy link
Author

Did you find what you needed? The ticket says closed is why I ask. I can provide example how to fix if still necessary.

@mootensai
Copy link
Owner

Hi, maybe your database schema is not right, did u use foreign keys? did your database have 2 primary keys? i've tried on my schema and it's working properly...

@mootensai
Copy link
Owner

this is my schema

-- --------------------------------------------------------
-- Host:                         127.0.0.1
-- Server version:               5.6.20 - MySQL Community Server (GPL)
-- Server OS:                    Win32
-- HeidiSQL Version:             9.1.0.4904
-- --------------------------------------------------------

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8mb4 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;

-- Dumping database structure for gii
CREATE DATABASE IF NOT EXISTS `gii` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `gii`;


-- Dumping structure for table gii.child1
CREATE TABLE IF NOT EXISTS `child1` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `created_at` datetime DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  `updated_by` int(11) DEFAULT NULL,
  `deleted_at` datetime DEFAULT NULL,
  `deleted_by` int(11) DEFAULT NULL,
  `lock` bigint(20) DEFAULT NULL,
  `master_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_child1_master_idx` (`master_id`),
  CONSTRAINT `fk_child1_master` FOREIGN KEY (`master_id`) REFERENCES `master` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Data exporting was unselected.


-- Dumping structure for table gii.child2
CREATE TABLE IF NOT EXISTS `child2` (
  `created_at` datetime DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  `updated_by` int(11) DEFAULT NULL,
  `deleted_at` datetime DEFAULT NULL,
  `deleted_by` int(11) DEFAULT NULL,
  `lock` bigint(20) DEFAULT NULL,
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `master_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_child2_master1_idx` (`master_id`),
  CONSTRAINT `fk_child2_master1` FOREIGN KEY (`master_id`) REFERENCES `master` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Data exporting was unselected.


-- Dumping structure for table gii.junction
CREATE TABLE IF NOT EXISTS `junction` (
  `master_id` int(11) NOT NULL,
  `master2_id` int(11) NOT NULL,
  PRIMARY KEY (`master_id`,`master2_id`),
  KEY `FK__master2` (`master2_id`,`master_id`),
  CONSTRAINT `FK__master` FOREIGN KEY (`master_id`) REFERENCES `master` (`id`),
  CONSTRAINT `FK__master2` FOREIGN KEY (`master2_id`) REFERENCES `master2` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Data exporting was unselected.


-- Dumping structure for table gii.master
CREATE TABLE IF NOT EXISTS `master` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `created_at` datetime DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  `updated_by` int(11) DEFAULT NULL,
  `deleted_at` datetime DEFAULT NULL,
  `deleted_by` int(11) DEFAULT NULL,
  `lock` bigint(20) DEFAULT NULL,
  `absensicol` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Data exporting was unselected.


-- Dumping structure for table gii.master2
CREATE TABLE IF NOT EXISTS `master2` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `Column` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Data exporting was unselected.
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants