Question

I'm using the following table:

CREATE TABLE `page` (
  `id` int(11) unsigned NOT NULL,
  `revision` float unsigned NOT NULL DEFAULT '1',
  `title` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `alias` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `text` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `parameters` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`,`revision`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Is it possible to use a two column primary key in RedBeanPHP? Normally you would use R::load('page', 1) but since I'm not only wanting id=?, but also revision=? this would not work.

I already read the documentation and some Stack Overflow questions, but I could't find any answer to this case.

Thanks your your help!

Was it helpful?

Solution

first of all no you cannot do it like you mentioned because RedBean requires each table to have a column named id (lowerCase) being auto-increment and primary key. Take a look at the schema documentation.

Next even if it would work, I wouldn't recommend doing so because you're violating DB normalization principles by including the revision in the same table. Most of the time you just need the latest revision but keeping all of them inside the same table just bloats your queries. So instead I'd advice to maybe try a solution like described in my Redbean ReBean module. It uses separate tables for revisions plus automated creation via triggers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top