Skip to content

Relation Model ​

DB Table Name{wp_db_prefix}fbs_relations
SchemaCheck Schema
Source Filefluent-boards/app/Models/Relation.php
Name SpaceFluentBoards\App\Models
ClassFluentBoards\App\Models\Relation

fbs_relations is the generic pivot table behind most many-to-many relations: board members, task assignees, watchers, labels, custom field values, task dependencies and folders. object_type says what object_id and foreign_id point to. The full list of types is in the schema.

Most of the time you work with these rows through relations such as Board::users(), Task::assignees() or Task::labels(). Use this model when you need to read or change the pivot row itself.

Attributes ​

AttributeData TypeComment
idINT UNSIGNEDPrimary key
object_idINT UNSIGNEDLeft side (for example board or task ID)
object_typeVARCHAR(100)Relation type, for example board_user, task_assignee
foreign_idINT UNSIGNEDRight side (for example user, label or board ID)
settingsTEXT NULLSerialized on write, unserialized on read
preferencesTEXT NULLSerialized on write, unserialized on read
created_atTIMESTAMP NULLHidden from toArray()
updated_atTIMESTAMP NULLHidden from toArray()

Serialization

The model serializes settings and preferences for you. Pass arrays, not maybe_serialize() output, or the value is serialized twice. When you attach rows through a relation ($task->assignees()->attach(...)), the pivot is written without the model, so there you must serialize yourself.

Usage ​

Please check Model Basic for common methods.

php
use FluentBoards\App\Models\Relation;

// Is user 5 a view-only member of board 1?
$membership = Relation::where('object_type', 'board_user')
    ->where('object_id', 1)
    ->where('foreign_id', 5)
    ->first();

$isViewer = $membership && !empty($membership->settings['is_viewer_only']);

// Make the user a board admin
if ($membership) {
    $settings = $membership->settings;
    $settings['is_admin'] = true;
    $membership->settings = $settings;
    $membership->save();
}

Use the constants in FluentBoards\App\Services\Constant (for example Constant::OBJECT_TYPE_BOARD_USER) instead of string literals.