Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

ORM Questions

posted by php guy 8 years ago

Hi, I love Flourish but Im having so many problems with !InnoDb and the ORM. I haven been using MyISAM for a while.

A very simple example

CREATE TABLE IF NOT EXISTS `countries` (
  `country_id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  PRIMARY KEY (`country_id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `users` (
  `user_id` int(11) NOT NULL AUTO_INCREMENT,
  `email` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `country_id` int(11) NOT NULL,
  PRIMARY KEY (`user_id`),
  UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

I already read the docs but I dont know how to get the name of the country in my user object

Can anyone show me?

I think you miss add a foreign key constrain to users table; something like this:

CREATE TABLE users (
  -- ...
  FOREIGN KEY country_id REFERENCES countries(country_id) ON DELETE RESTRICT ON UPDATE CASCADE
);
posted by xoan 8 years ago

Once you have your foreign key constraint set up, you can get the country name via the following code:

$user->createCountry()->getName();
posted by wbond 8 years ago

How many queries are need to get the whole data?

posted by anonymous 8 years ago

1 database call is made per fRecordSet::build() call, and 1 database call is made per new fActiveRecord() that is not already loaded into memory.

You can see the exact queries by calling:

fORMDatabase::retrieve()->enableDebugging(TRUE);
posted by wbond 8 years ago