Nette\InvalidArgumentException pri ziskavani dat ze SELECTu
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- vosy
- Člen | 532
ahoj mam tyto tri tabulky
CREATE TABLE IF NOT EXISTS `vozidla` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nazev` varchar(50) COLLATE utf8_czech_ci NOT NULL,
`nacist` enum('ano','ne') COLLATE utf8_czech_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=6 ;
--
-- Vypisuji data pro tabulku `vozidla`
--
INSERT INTO `vozidla` (`id`, `nazev`, `nacist`) VALUES
(1, 'Motocykl', 'ano'),
(2, 'Tříkolka', 'ne'),
(3, 'Quad', 'ano'),
(4, 'Skútr', 'ano'),
(5, 'Elektrické kolo', 'ano');
CREATE TABLE IF NOT EXISTS `znacky` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`key` varchar(50) COLLATE utf8_czech_ci NOT NULL,
`vozidla_id` int(11) NOT NULL,
`nazev` varchar(50) COLLATE utf8_czech_ci NOT NULL,
UNIQUE KEY `key` (`key`,`vozidla_id`),
UNIQUE KEY `id` (`id`),
KEY `vozidla_id` (`vozidla_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=2 ;
--
-- Vypisuji data pro tabulku `znacky`
--
INSERT INTO `znacky` (`id`, `key`, `vozidla_id`, `nazev`) VALUES
(1, 'Harley Davidson', 1, 'Harley Davidson');
--
-- Omezení pro exportované tabulky
--
--
-- Omezení pro tabulku `znacky`
--
ALTER TABLE `znacky`
ADD CONSTRAINT `znacky_ibfk_2` FOREIGN KEY (`vozidla_id`) REFERENCES `vozidla` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
CREATE TABLE IF NOT EXISTS `modely` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`key` varchar(100) COLLATE utf8_czech_ci NOT NULL,
`znacky_id` int(11) NOT NULL,
`nazev` varchar(100) COLLATE utf8_czech_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `key` (`key`,`znacky_id`),
KEY `znacky_id` (`znacky_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=4 ;
--
-- Vypisuji data pro tabulku `modely`
--
INSERT INTO `modely` (`id`, `key`, `znacky_id`, `nazev`) VALUES
(1, 'FL', 1, 'FL'),
(2, 'FLD', 1, 'FLD'),
(3, 'FLH', 1, 'FLH');
--
-- Omezení pro exportované tabulky
--
--
-- Omezení pro tabulku `modely`
--
ALTER TABLE `modely`
ADD CONSTRAINT `modely_ibfk_2` FOREIGN KEY (`znacky_id`) REFERENCES `znacky` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
a pak mam
$tab = \Glb::$TABS['modely'];
$r = $this->db->table($tab)
->where('znacky_id=?', 1)
->order('id ASC');
if($r)
{
foreach($r as $v0)
{
print_r($v0['znacky']['vozidla']['id']);
a vysledek je
Nette\InvalidArgumentException
Argument count does not match placeholder count.
.../app/AdminModule/models/StrojeRepository.php:348 source Nette\Database\Table\ActiveRow-> offsetGet (arguments)
338: {
339: $tab = \Glb::$TABS['modely'];
340: $r = $this->db->table($tab)
341: ->where('znacky_id=?', 1)
342: ->order('id ASC');
343:
344: if($r)
345: {
346: foreach($r as $v0)
347: {
--------> 348: print_r($v0['znacky']['vozidla']['id']);
349: $arrUrl['type'] = $v0->znacky->vozidla->id;
350: $arrUrl['Marke'] = $v0->znacky->key;
351: $arrUrl['Verkaufsbezeichnung'] = $v0->key;
352: $idModelu = $v0->id;
$key
"znacky" (6)