0

I am using the redbeanPHP ORM and mysql. I have the following table:

CREATE TABLE `mast` (
 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
 `note` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
 `geolocation` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
 `location` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
 `zip` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
 `state` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
 `app` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
 PRIMARY KEY (`id`),
 UNIQUE KEY `UQ_84a93b55f688c94f73092dba1b9590c41a92cbf5` ('app')
) ENGINE=InnoDB AUTO_INCREMENT=98 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

I want to insert records into the 'mast' table providing they are unique with respect to both of the 2 fields listed above. In other words if either 'geolocation' or 'app' is a duplicate, I don't want to insert the associated record.

I am using following php code to create the 2 unique fields:

       $mast= R::dispense('mast');
       $mast->setMeta("buildcommand.unique" , array(array('geolocation')));

            $mast ->import($resultsarray);
            $mast->setMeta("buildcommand.unique" , array(array('app')));


            $id = R::store($mast); // DUMMY BEAN

A unique index is only being created for the 'app' field . Is there a way to set them both as unique in redbean?

user1592380
  • 34,265
  • 92
  • 284
  • 515

1 Answers1

0

From the documentation it should work like the following:

$mast = R::dispense('mast');
$mast->setMeta("buildcommand.unique.0", array('geolocation', 'app'));
$mast->import($resultsarray);
$id = R::store($mast);

In your code you just overwrote the value for build command.unique.

kekub
  • 872
  • 6
  • 11