Laravel在关系中链接数据透视表

时间:2015-04-02 06:36:52

标签: laravel many-to-many eloquent pivot-table

是否有可能在laravel中追逐枢轴表?我有以下结构:

Computer 
ComputerSoftwareVersion
SoftwareVersion
Software

计算机可以有许多具有给定版本的软件,因此计算机和软件之间的链接由两个枢轴表完成:

Computer <1:n> ComputerSoftwareVersions <n:1> SoftwareVersion <n:1> Software

这是否可以用laravel雄辩的方式进行?

以下是相关表格的数据库架构:

CREATE TABLE `glpi_computers_softwareversions` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `computers_id` INT(11) NOT NULL DEFAULT '0',
    `softwareversions_id` INT(11) NOT NULL DEFAULT '0',
    `is_deleted_computer` TINYINT(1) NOT NULL DEFAULT '0',
    `is_template_computer` TINYINT(1) NOT NULL DEFAULT '0',
    `entities_id` INT(11) NOT NULL DEFAULT '0',
    `is_deleted` TINYINT(1) NOT NULL DEFAULT '0',
    `is_dynamic` TINYINT(1) NOT NULL DEFAULT '0',
    PRIMARY KEY (`id`),
    UNIQUE INDEX `unicity` (`computers_id`, `softwareversions_id`),
    INDEX `softwareversions_id` (`softwareversions_id`),
    INDEX `computers_info` (`entities_id`, `is_template_computer`, `is_deleted_computer`),
    INDEX `is_template` (`is_template_computer`),
    INDEX `is_deleted` (`is_deleted_computer`),
    INDEX `is_dynamic` (`is_dynamic`)
);

CREATE TABLE `glpi_softwareversions` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `entities_id` INT(11) NOT NULL DEFAULT '0',
    `is_recursive` TINYINT(1) NOT NULL DEFAULT '0',
    `softwares_id` INT(11) NOT NULL DEFAULT '0',
    `states_id` INT(11) NOT NULL DEFAULT '0',
    `name` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8_unicode_ci',
    `comment` TEXT NULL COLLATE 'utf8_unicode_ci',
    `operatingsystems_id` INT(11) NOT NULL DEFAULT '0',
    PRIMARY KEY (`id`),
    INDEX `name` (`name`),
    INDEX `softwares_id` (`softwares_id`),
    INDEX `states_id` (`states_id`),
    INDEX `entities_id` (`entities_id`),
    INDEX `is_recursive` (`is_recursive`),
    INDEX `operatingsystems_id` (`operatingsystems_id`)
);

CREATE TABLE `glpi_softwares` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `entities_id` INT(11) NOT NULL DEFAULT '0',
    `is_recursive` TINYINT(1) NOT NULL DEFAULT '0',
    `name` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8_unicode_ci',
    `comment` TEXT NULL COLLATE 'utf8_unicode_ci',
    `locations_id` INT(11) NOT NULL DEFAULT '0',
    `users_id_tech` INT(11) NOT NULL DEFAULT '0',
    `groups_id_tech` INT(11) NOT NULL DEFAULT '0',
    `is_update` TINYINT(1) NOT NULL DEFAULT '0',
    `softwares_id` INT(11) NOT NULL DEFAULT '0',
    `manufacturers_id` INT(11) NOT NULL DEFAULT '0',
    `is_deleted` TINYINT(1) NOT NULL DEFAULT '0',
    `is_template` TINYINT(1) NOT NULL DEFAULT '0',
    `template_name` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8_unicode_ci',
    `date_mod` DATETIME NULL DEFAULT NULL,
    `users_id` INT(11) NOT NULL DEFAULT '0',
    `groups_id` INT(11) NOT NULL DEFAULT '0',
    `ticket_tco` DECIMAL(20,4) NULL DEFAULT '0.0000',
    `is_helpdesk_visible` TINYINT(1) NOT NULL DEFAULT '1',
    `softwarecategories_id` INT(11) NOT NULL DEFAULT '0',
    `is_valid` TINYINT(1) NOT NULL DEFAULT '1',
    PRIMARY KEY (`id`),
    INDEX `date_mod` (`date_mod`),
    INDEX `name` (`name`),
    INDEX `is_template` (`is_template`),
    INDEX `is_update` (`is_update`),
    INDEX `softwarecategories_id` (`softwarecategories_id`),
    INDEX `entities_id` (`entities_id`),
    INDEX `manufacturers_id` (`manufacturers_id`),
    INDEX `groups_id` (`groups_id`),
    INDEX `users_id` (`users_id`),
    INDEX `locations_id` (`locations_id`),
    INDEX `users_id_tech` (`users_id_tech`),
    INDEX `softwares_id` (`softwares_id`),
    INDEX `is_deleted` (`is_deleted`),
    INDEX `is_helpdesk_visible` (`is_helpdesk_visible`),
    INDEX `groups_id_tech` (`groups_id_tech`)
);

0 个答案:

没有答案