Is RedBean ORM able to create unique keys?

三世轮回 提交于 2019-12-03 16:03:13
Tim Withers

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

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

Plugging in what you have:

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

If that doesn't work, you may have to read the actual code under the setMeta function and see what is actually going on.

To do this on an existing table it is sufficient to "store" an empty bean like this- no data needs to be added to the DB:

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

(Word of warning, if you freeze after doing this, you're not guaranteed to have all your columns)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!