CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 5.3 Chiffon API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 5.3
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
      • Driver
      • Exception
      • Expression
      • Log
      • Query
      • Retry
      • Schema
      • Statement
      • Type
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Class ForeignKey

ForeignKey metadata object

Models a database foreign key constraint

Namespace: Cake\Database\Schema

Constants

  • CASCADE ¶
    'cascade'
  • string
    CHECK ¶
    TableSchema::CONSTRAINT_CHECK
  • DEFERRED ¶
    'DEFERRABLE INITIALLY DEFERRED'
  • string
    FOREIGN ¶
    TableSchema::CONSTRAINT_FOREIGN
  • IMMEDIATE ¶
    'DEFERRABLE INITIALLY IMMEDIATE'
  • NOT_DEFERRED ¶
    'NOT DEFERRABLE'
  • NO_ACTION ¶
    'noAction'
  • string
    PRIMARY ¶
    TableSchema::CONSTRAINT_PRIMARY
  • RESTRICT ¶
    'restrict'
  • SET_DEFAULT ¶
    'setDefault'
  • SET_NULL ¶
    'setNull'
  • string
    UNIQUE ¶
    TableSchema::CONSTRAINT_UNIQUE

Property Summary

  • $deferrable protected
    string|null
  • $delete protected
    ?string

    The action to take when the referenced row is deleted.

  • $update protected
    ?string

    The action to take when the referenced row is updated.

  • $validActions protected
    array<string>

    An allow list of valid actions

Method Summary

  • __construct() public

    Constructor

  • getColumns() public

    Gets the constraint columns.

  • getDeferrable() public

    Gets deferrable mode for the foreign key.

  • getDelete() public

    Gets ON DELETE action for the foreign key.

  • getName() public

    Gets the constraint name.

  • getReferencedColumns() public

    Gets the foreign key referenced columns.

  • getReferencedTable() public

    Gets the foreign key referenced table.

  • getType() public

    Gets the constraint type.

  • getUpdate() public

    Gets ON UPDATE action for the foreign key.

  • normalizeAction() protected

    From passed value checks if it's correct and fixes if needed

  • normalizeDeferrable() protected

    From passed value checks if it's correct and fixes if needed

  • setColumns() public

    Sets the constraint columns.

  • setDeferrable() public

    Sets deferrable mode for the foreign key.

  • setDelete() public

    Sets ON DELETE action for the foreign key.

  • setName() public

    Sets the constraint name.

  • setReferencedColumns() public

    Sets the foreign key referenced columns.

  • setReferencedTable() public

    Sets the foreign key referenced table.

  • setType() public

    Sets the constraint type.

  • setUpdate() public

    Sets ON UPDATE action for the foreign key.

  • toArray() public

    Converts the foreign key to an array that is compatible with the constructor.

Method Detail

__construct() ¶ public

__construct(string $name, array<string> $columns, ?string $referencedTable = null, array<string> $referencedColumns = [], ?string $delete = null, ?string $update = null, ?string $deferrable = null)

Constructor

Parameters
string $name

The name of the index.

array<string> $columns

The columns to index.

?string $referencedTable optional

The columns to index.

array<string> $referencedColumns optional

The columns in $referencedTable that this key references.

?string $delete optional

The action to take when the referenced row is deleted.

?string $update optional

The action to take when the referenced row is updated.

?string $deferrable optional

getColumns() ¶ public

getColumns(): ?array<string>

Gets the constraint columns.

Returns
?array<string>

getDeferrable() ¶ public

getDeferrable(): ?string

Gets deferrable mode for the foreign key.

Returns
?string

getDelete() ¶ public

getDelete(): string|null

Gets ON DELETE action for the foreign key.

Returns
string|null

getName() ¶ public

getName(): ?string

Gets the constraint name.

Returns
?string

getReferencedColumns() ¶ public

getReferencedColumns(): array<string>

Gets the foreign key referenced columns.

Returns
array<string>

getReferencedTable() ¶ public

getReferencedTable(): ?string

Gets the foreign key referenced table.

Returns
?string

getType() ¶ public

getType(): string

Gets the constraint type.

Returns
string

getUpdate() ¶ public

getUpdate(): string|null

Gets ON UPDATE action for the foreign key.

Returns
string|null

normalizeAction() ¶ protected

normalizeAction(string $action): string

From passed value checks if it's correct and fixes if needed

Parameters
string $action

Action

Returns
string
Throws
InvalidArgumentException

normalizeDeferrable() ¶ protected

normalizeDeferrable(string $deferrable): string

From passed value checks if it's correct and fixes if needed

Parameters
string $deferrable

Deferrable

Returns
string
Throws
InvalidArgumentException

setColumns() ¶ public

setColumns(array<string>|string $columns): $this

Sets the constraint columns.

Parameters
array<string>|string $columns

Columns

Returns
$this

setDeferrable() ¶ public

setDeferrable(string $deferrable): $this

Sets deferrable mode for the foreign key.

Parameters
string $deferrable

Constraint

Returns
$this

setDelete() ¶ public

setDelete(string $delete): $this

Sets ON DELETE action for the foreign key.

Parameters
string $delete

On Delete

Returns
$this

setName() ¶ public

setName(string $name): $this

Sets the constraint name.

Parameters
string $name

Name

Returns
$this

setReferencedColumns() ¶ public

setReferencedColumns(array<string>|string $referencedColumns): $this

Sets the foreign key referenced columns.

Parameters
array<string>|string $referencedColumns

Referenced columns

Returns
$this

setReferencedTable() ¶ public

setReferencedTable(string $table): $this

Sets the foreign key referenced table.

Parameters
string $table

The table this KEY is pointing to

Returns
$this

setType() ¶ public

setType(string $type): $this

Sets the constraint type.

Parameters
string $type

Type

Returns
$this

setUpdate() ¶ public

setUpdate(string $update): $this

Sets ON UPDATE action for the foreign key.

Parameters
string $update

On Update

Returns
$this

toArray() ¶ public

toArray(): array<string, mixed>

Converts the foreign key to an array that is compatible with the constructor.

Returns
array<string, mixed>

Property Detail

$deferrable ¶ protected

Type
string|null

$delete ¶ protected

The action to take when the referenced row is deleted.

Type
?string

$update ¶ protected

The action to take when the referenced row is updated.

Type
?string

$validActions ¶ protected

An allow list of valid actions

Type
array<string>
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs