Nextcloud PHP API (master)

OneToOne
in package

Read onlyYes
FinalYes

Attribute for mapping two properties together in a one-to-one relation.

Example of a unidirectional relationship.

#[Entity(name: 'product']
final class Product {
    #[Id]
    #[Column(name: 'id', type: ColumnType::Bigint)]
    public ?int $id = null;

    #[OneToOne(targetEntity: Shipment::class)]
    #[JoinColumn(name: 'shipment_id', referencedColumnName: 'id')]
    public Shipment|null $shipment = null;
}

#[Entity(name: 'shipment']
final class Shipment {
    #[Id]
    #[Column(name: 'id', type: ColumnType::Bigint)]
    public ?int $id = null;
}

Example of a bidirectional relationship where Cart owns the relationship.

#[Entity(name: 'customer']
final class Customer {
    #[Id]
    #[Column(name: 'id', type: ColumnType::Bigint)]
    public ?int $id = null;

    #[OneToOne(targetEntity: Cart::class, mappedBy: 'customer')]
    #[JoinColumn(name: 'cart_id', referencedColumnName: 'id')]
    public Cart|null $cart = null;
}

#[Entity(name: 'cart']
final class Cart {
    #[Id]
    #[Column(name: 'id', type: ColumnType::Bigint)]
    public ?int $id = null;

    #[OneToOne(targetEntity: Customer::class, invertedBy: 'cart')]
    #[JoinColumn(name: 'customer_id', referencedColumnName: 'id')]
    public Customer|null $customer;
}
Tags
since
35.0.0
Attributes
#[Attribute]
\Attribute::TARGET_PROPERTY
#[Consumable]
$since: '35.0.0'

Table of Contents

Properties

$invertedBy  : non-empty-string|null
$mappedBy  : non-empty-string|null
$targetEntity  : class-string

Methods

__construct()  : mixed

Properties

$invertedBy

public non-empty-string|null $invertedBy = null

$mappedBy

public non-empty-string|null $mappedBy = null

$targetEntity

public class-string $targetEntity

Methods

__construct()

public __construct(string $targetEntity[, string|null $mappedBy = null ][, string|null $invertedBy = null ]) : mixed
Parameters
$targetEntity : string
$mappedBy : string|null = null
$invertedBy : string|null = null
Tags
since
35.0.0
On this page

Search results