• Start

v1 (stable)

/

Methods

insertRelation

Insert one or multiple relations in the database using the insertRelation method with the SurrealDB PHP SDK.

Inserts one or multiple relations in the database.

Method Syntax
$db->insertRelation($thing, $data)

Arguments

Type

Description

thing

string or Table

Target table to insert the relation to.

data

array

An array of relations to insert.

// Insert a single relation
$relation = $db->insertRelation('person', [
	"id" => new RecordId('person', 'tobie'),
	"in" => new RecordId('company', 'surreal'),
	"out" => new RecordId('role', 'founder'),
]);

// Insert multiple relations
$relations = $db->insertRelation('person', [
	[
		"id" => new RecordId('person', 'tobie'),
		"in" => new RecordId('company', 'surreal'),
		"out" => new RecordId('role', 'founder'),
	],
	[
		"id" => new RecordId('person', 'jaime'),
		"in" => new RecordId('company', 'surreal'),
		"out" => new RecordId('role', 'cofounder'),
	],
]);

Was this page helpful?