Is RedBean ORM able to create unique keys?

I want RedBean to create unique keys / indexes when creating a schema. The following code - against how I understand the documentation - do not do this:

R :: Installation ('SQLite: rss_loader.db3');

$bean = R::findOne(IMG);
if (!$bean->id) {
    $bean = R::dispense(IMG);
    $bean->setMeta("buildcommand.unique.0", array('url'));
    $bean->url      = 'text';
    R::store($bean);
    $bean->wipe();

    R::freeze(); //no more schema changes!
}

What happens in sqlite ist this:

create table img (id integer primary key autoincrement, url) 

What I expected was as follows:

create table img (id integer primary key autoincrement, url text unique) 

Can this be done without writing SQL in RedBean?

+5
source share
1 answer

What version of Redbean are you using? It looks like they updated buildcommandin the latest version. This is what the manual says:

$bean->setMeta("buildcommand.unique" , array(array($property1, $property2)));

Inclusion of what you have:

$bean->setMeta("buildcommand.unique" , array(array('url')));

If this does not work, you may have to read the actual code under the function setMetaand see what actually happens.

, "" bean, : :

$bean = R::dispense(IMG);
$bean->setMeta("buildcommand.unique", array(array(...)));
R::store($bean);

( , , )

+3

All Articles