Tahání dat z jiné tabulky a výpis pro editaci

jAkErCZ
Člen | 321
+
-2
-

Čau, mám 3 tabulky configure configure_image_groups a configure_product_color

DROP TABLE IF EXISTS `configure`;
CREATE TABLE `configure` (
  `cofigure_id` int(11) NOT NULL AUTO_INCREMENT,
  `code` varchar(10) DEFAULT NULL,
  `url` varchar(50) DEFAULT NULL,
  `title` varchar(20) NOT NULL,
  `short_description` varchar(255) DEFAULT NULL,
  `price` float DEFAULT NULL,
  `images_count` int(11) DEFAULT NULL,
  `hidden` int(11) DEFAULT NULL,
  PRIMARY KEY (`cofigure_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `configure` (`cofigure_id`, `code`, `url`, `title`, `short_description`, `price`, `images_count`, `hidden`) VALUES
(1,	'159753',	'perito',	'Perito',	'Nejlepší dveře na světě',	14200,	1,	0);

DROP TABLE IF EXISTS `configure_image_groups`;
CREATE TABLE `configure_image_groups` (
  `product_image_group_id` int(11) NOT NULL AUTO_INCREMENT,
  `cofigure_id` int(11) NOT NULL,
  PRIMARY KEY (`product_image_group_id`),
  KEY `cofigure_id` (`cofigure_id`),
  CONSTRAINT `configure_image_groups_ibfk_1` FOREIGN KEY (`cofigure_id`) REFERENCES `configure` (`cofigure_id`),
  CONSTRAINT `configure_image_groups_ibfk_2` FOREIGN KEY (`product_image_group_id`) REFERENCES `configure_product_color` (`product_image_group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `configure_image_groups` (`product_image_group_id`, `cofigure_id`) VALUES
(1,	1);

DROP TABLE IF EXISTS `configure_product_color`;
CREATE TABLE `configure_product_color` (
  `img_color_id` int(11) NOT NULL AUTO_INCREMENT,
  `product_image_group_id` int(11) DEFAULT NULL,
  `title` varchar(20) DEFAULT NULL,
  `price` float DEFAULT NULL,
  `color_url` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`img_color_id`),
  KEY `product_image_group_id` (`product_image_group_id`),
  CONSTRAINT `configure_product_color_ibfk_1` FOREIGN KEY (`product_image_group_id`) REFERENCES `configure_image_groups` (`product_image_group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `configure_product_color` (`img_color_id`, `product_image_group_id`, `title`, `price`, `color_url`) VALUES
(1,	1,	'Oranžová',	250,	'test/test.png');

Ale za boha nemůžu přijít na to jak si ty data mám vytáhnout z té tabulky configure_product_color dle product_image_group_id které je zase taháno z db configure_image_groups a tam je to pomocí cofigure_id směřováno na db configure

Samotné data z configure se mi vypisují a vše funguje ale jakmile přejdu na barevnost tak chci aby se tam nějak vypsaly.. Jelikož jsem nepřišel na to jak použít form který by je vypsal všechny tak se chci zeptat tady…
Jak bych je mohl vypsat do šablony?
A jak vytáhnout z té db?

$colors =  $this->database->table(self::TABLE_NAME_COLOR_GROUP);
        $colors->where('configure_product_color.product_image_group_id =',$cofigure_id);
        return $colors;

Tento kód mi hází
No reference found for $configure_image_groups->configure_product_color. ale přitom v db jsou spojeny.

Díky všem za pomoc

David Matějka
Moderator | 6445
+
0
-

1. ta struktura db je divna,

CONSTRAINT `configure_image_groups_ibfk_2` FOREIGN KEY (`product_image_group_id`) REFERENCES `configure_product_color` (`product_image_group_id`)

tam myslim vubec byt nema.

2. kdyz chces vybirat z tabulky configure_product_color, tak nemuzes ten query skladat ze strany configure_image_groups

3. kdyz chces filtrovat podle configure_id, tak nemuzes filtrovat podle product_image_group_id

jAkErCZ
Člen | 321
+
0
-

David Matějka napsal(a):

1. ta struktura db je divna,

CONSTRAINT `configure_image_groups_ibfk_2` FOREIGN KEY (`product_image_group_id`) REFERENCES `configure_product_color` (`product_image_group_id`)

tam myslim vubec byt nema.

2. kdyz chces vybirat z tabulky configure_product_color, tak nemuzes ten query skladat ze strany configure_image_groups

3. kdyz chces filtrovat podle configure_id, tak nemuzes filtrovat podle product_image_group_id

  1. Však to je cizí klíč který se napojuje na db colors
  2. Dobře takže ji mám skládat od kut? ze strany configure? nebo color?
  3. Jakto když v tom color mám jen id obrázku a pak id dané groupy

Editoval jAkErCZ (28. 2. 2018 14:45)

David Matějka
Moderator | 6445
+
0
-
  1. v tabulce configure_image_groups mas PK product_image_group_id. soucasne je to vsak jako FK do tabulky configure_product_color. a z tabulky configure_product_color je product_image_group_id zas jako FK do configure_image_groups
  2. ze strany color
  3. se koukni na ten kod
$colors->where('configure_product_color.product_image_group_id =',$cofigure_id);

opravdu ti neprijde divny, ze kontrolujes rovnost mezi product_image_group_id a configure_id?

jAkErCZ
Člen | 321
+
0
-

David Matějka napsal(a):

  1. v tabulce configure_image_groups mas PK product_image_group_id. soucasne je to vsak jako FK do tabulky configure_product_color. a z tabulky configure_product_color je product_image_group_id zas jako FK do configure_image_groups
  2. ze strany color
  3. se koukni na ten kod
$colors->where('configure_product_color.product_image_group_id =',$cofigure_id);

opravdu ti neprijde divny, ze kontrolujes rovnost mezi product_image_group_id a configure_id?

  1. Ajo máš pravdu nechápu proč jsem tam přidával další klíč… Smazal jsem ho :)
  2. Ok takže ze strany color ale jak je budu kontrolovat když tam je jen id groups?
  3. Ano už to též vidím dotazuji se na něco nesmyslného..

Editoval jAkErCZ (28. 2. 2018 14:56)

David Matějka
Moderator | 6445
+
+1
-
$this->database->table('configure_product_color')
	->where('product_image_group.cofigure_id', $cofigure_id)
jAkErCZ
Člen | 321
+
0
-

David Matějka napsal(a):

$this->database->table('configure_product_color')
	->where('product_image_group.cofigure_id', $cofigure_id)

Ok a jak ty barvy vykreslím v šabloně? Jelikož přes form to nepůjde… jelikož ke každému produktu můžu mít třeba i 3 barvy

David Matějka
Moderator | 6445
+
0
-

proc by to pres formular neslo? jak to ma fungovat? budes tam mit seznam produktu a u kazdeho chces vybirat 0-N barev?

v tom pripade si udelej pro kazdy produkt checkbox list

jAkErCZ
Člen | 321
+
0
-

David Matějka napsal(a):

proc by to pres formular neslo? jak to ma fungovat? budes tam mit seznam produktu a u kazdeho chces vybirat 0-N barev?

v tom pripade si udelej pro kazdy produkt checkbox list

No mám to dělaný zatím tak že mám datagrid a v něm možnost barevnost a na to když kliknu měly by se mi vykreslit všechny dostupné barvy… ALe netuším jak je všechny afektivně vykreslit

jAkErCZ
Člen | 321
+
0
-

David Matějka napsal(a):

$this->database->table('configure_product_color')
	->where('product_image_group.cofigure_id', $cofigure_id)

Jinak mi to hodilo ještě…

No reference found for $configure_product_color->configure_image_groups

Na

return $this->database->table('configure_product_color')
           ->where('configure_image_groups.configure_id', $configure_id);
Duch.Veliky
Člen | 68
+
0
-

No reference found for $configure_product_color->configure_image_groups znamená, že tam nejspíš nemáš cizí klíč v databázi