Created
August 22, 2011 10:30
-
-
Save norbe/1162101 to your computer and use it in GitHub Desktop.
NotORM test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NotORM test based on OSI DAYS example (http://www.notorm.com/static/osidays2010.zip). | |
For testing purpose I was add author_id column to TAG table and then try to load applications filtered by application.author.name and application.tag.author.name in the same time. | |
Problem is that NotORM doesn't use aliases, so I can't work with one table more than once (from another context). | |
Do you know how to solve it? Please update my index.php file.. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
David Grudl: Dibi | |
- PHP | |
- MySQL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
David Grudl: Dibi | |
- PHP | |
- MySQL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include "NotORM.php"; | |
$pdo = new PDO("mysql:dbname=software", "ODBC"); | |
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); | |
$cache = new NotORM_Cache_File("notorm.cache"); | |
$db = new NotORM($pdo, null, $cache); | |
foreach ($db->application() | |
// conditions do not work together | |
->where("author.name", "David Grudl") | |
->where("application_tag:tag.author.name", "David Grudl") | |
as $application) { | |
echo $application->author["name"] . ": "; | |
echo $application["title"] . "\n"; | |
foreach ($application->application_tag() as $application_tag) { | |
echo "- " . $application_tag->tag["name"] . "\n"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include "NotORM.php"; | |
$pdo = new PDO("mysql:dbname=software", "ODBC"); | |
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); | |
$cache = new NotORM_Cache_File("notorm.cache"); | |
$db = new NotORM($pdo, null, $cache); | |
foreach($db->application() | |
->where("application.id", $db | |
->application_tag("tag.author.name", "David Grudl") | |
->select("application_id") | |
) | |
->where("application.id", $db | |
->application("author.name", "David Grudl") | |
->select("application.id") | |
) as $application) { | |
echo $application->author["name"] . ": "; | |
echo $application["title"] . "\n"; | |
foreach ($application->application_tag() as $application_tag) { | |
echo "- " . $application_tag->tag["name"] . "\n"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Adminer 3.0.0-dev MySQL dump | |
SET NAMES utf8; | |
SET foreign_key_checks = 0; | |
SET time_zone = 'SYSTEM'; | |
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; | |
CREATE DATABASE `software` /*!40100 DEFAULT CHARACTER SET utf8 */; | |
USE `software`; | |
CREATE TABLE `application` ( | |
`id` int(11) NOT NULL, | |
`author_id` int(11) NOT NULL COMMENT 'Author', | |
`title` varchar(50) NOT NULL COMMENT 'Title', | |
`web` varchar(100) NOT NULL COMMENT 'Web', | |
`slogan` text NOT NULL COMMENT 'Slogan', | |
PRIMARY KEY (`id`), | |
KEY `application_ibfk_1` (`author_id`), | |
KEY `application_title` (`title`), | |
CONSTRAINT `application_ibfk_1` FOREIGN KEY (`author_id`) REFERENCES `author` (`id`) | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Applications'; | |
INSERT INTO `application` (`id`, `author_id`, `title`, `web`, `slogan`) VALUES | |
(1, 11, 'Adminer', 'http://www.adminer.org/', 'Database management in single PHP file'), | |
(2, 11, 'JUSH', 'http://jush.sourceforge.net/', 'JavaScript Syntax Highlighter'), | |
(3, 12, 'Nette', 'http://nettephp.com/', 'Nette Framework for PHP 5'), | |
(4, 12, 'Dibi', 'http://dibiphp.com/', 'Database Abstraction Library for PHP 5'); | |
CREATE TABLE `application_tag` ( | |
`application_id` int(11) NOT NULL COMMENT 'Application', | |
`tag_id` int(11) NOT NULL COMMENT 'Tag', | |
PRIMARY KEY (`application_id`,`tag_id`), | |
KEY `application_tag_ibfk_3` (`tag_id`), | |
CONSTRAINT `application_tag_ibfk_2` FOREIGN KEY (`application_id`) REFERENCES `application` (`id`) ON DELETE CASCADE, | |
CONSTRAINT `application_tag_ibfk_3` FOREIGN KEY (`tag_id`) REFERENCES `tag` (`id`) | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Applications - tags'; | |
INSERT INTO `application_tag` (`application_id`, `tag_id`) VALUES | |
(1, 21), | |
(3, 21), | |
(4, 21), | |
(1, 22), | |
(4, 22), | |
(2, 23); | |
CREATE TABLE `author` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`name` varchar(30) NOT NULL COMMENT 'Name', | |
`web` varchar(100) NOT NULL COMMENT 'Web', | |
`born` date DEFAULT NULL COMMENT 'Born', | |
PRIMARY KEY (`id`) | |
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 COMMENT='Authors'; | |
INSERT INTO `author` (`id`, `name`, `web`, `born`) VALUES | |
(11, 'Jakub Vrana', 'http://www.vrana.cz/', NULL), | |
(12, 'David Grudl', 'http://davidgrudl.com/', NULL); | |
CREATE TABLE `tag` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`name` varchar(20) NOT NULL COMMENT 'Name', | |
PRIMARY KEY (`id`) | |
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8 COMMENT='Tags'; | |
INSERT INTO `tag` (`id`, `name`) VALUES | |
(21, 'PHP'), | |
(22, 'MySQL'), | |
(23, 'JavaScript'); | |
-- changes from original file | |
ALTER TABLE `tag` ADD `author_id` INT( 11 ) NULL , | |
ADD INDEX ( `author_id` ); | |
ALTER TABLE `tag` ADD FOREIGN KEY ( `author_id` ) REFERENCES `software`.`author` ( | |
`id` | |
); | |
UPDATE `software`.`tag` SET `author_id` = '11' WHERE `tag`.`id` =21; | |
UPDATE `software`.`tag` SET `author_id` = '12' WHERE `tag`.`id` =22; | |
UPDATE `software`.`tag` SET `author_id` = '11' WHERE `tag`.`id` =23; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment