---
name: "Alzabo::Create::ForeignKey"
section: "3pm"
platform: "linux"
package: "libalzabo-perl"
version: "0.92-6"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Alzabo::Create::ForeignKey"
---

# Alzabo::Create::ForeignKey(3pm)

Foreign key objects for schema creation.

## NAME

Alzabo::Create::ForeignKey - Foreign key objects for schema creation.

## SYNOPSIS

```
  use Alzabo::Create::ForeignKey;
```

## DESCRIPTION

A foreign key is an object defined by several properties.  It represents a relationship from a column or columns in one table to a column or columns in another table.

This relationship is defined by its cardinality (one to one, one to many, or many to one) and its dependencies (whether or not table X is dependent on table Y, and vice versa).

Many to many relationships are not allowed.  However, you may indicate such a relationship when using the Alzabo::Create::Schema-\>add\_relation method method, and it will create the necessary intermediate linking table for you.

## INHERITS FROM

`"Alzabo::ForeignKey"`

Note: all relevant documentation from the superclass has been merged into this document.

## METHODS

### new

The constructor takes the following parameters:

- •

  columns\_from =\> `"Alzabo::Create::Column"` object(s)

- •

  columns\_to =\> `"Alzabo::Create::Column"` object(s)

  These two parameters may be either a single column or a reference to an array columns.  The number of columns in the two parameters must match.

- •

  cardinality =\> \[1, 1\], \[1, 'n'\], or \['n', 1\]

- •

  from\_is\_dependent =\> `$boolean`

- •

  to\_is\_dependent =\> `$boolean`

- •

  comment =\> `$comment`

  An optional comment.

It returns a new `"Alzabo::Create::ForeignKey"` object.

Throws: `"Alzabo::Exception::Params"`

### table\_from

### table\_to

Returns the relevant `"Alzabo::Create::Table"` object.

### columns\_from

### columns\_to

Returns the relevant `"Alzabo::Create::Column"` object(s) for the property as an array.

### column\_pairs

Returns an array of array references.  The references are to two column array of `"Alzabo::Create::Column"` objects.  These two columns correspond in the tables being linked together.

### set\_columns\_from ("Alzabo::Create::Column" object(s))

Sets the column(s) that the relation is from.  This can be either a single column object or a reference to an array of column objects.

Throws: `"Alzabo::Exception::Params"`

### set\_columns\_to ("Alzabo::Create::Column" object(s))

Sets the column(s) that the relation is to.  This can be either a single column object or a reference to an array of column objects.

Throws: `"Alzabo::Exception::Params"`

### cardinality

Returns a two element array containing the two portions of the cardinality of the relationship.  Each portion will be either '1' or 'n'.

### from\_is\_dependent

### to\_is\_dependent

Returns a boolean value indicating whether there is a dependency from one table to the other.

### is\_one\_to\_one

### is\_one\_to\_many

### is\_many\_to\_one

Returns a boolean value indicating what kind of relationship the object represents.

### set\_cardinality (\\@cardinality) see above for details

Sets the cardinality of the foreign key.

Throws: `"Alzabo::Exception::Params"`

### set\_from\_is\_dependent ($boolean)

Indicates whether or not the first table in the foreign key is dependent on the other (i.e. whether the 'from' table is dependent on the 'to' table).

### set\_to\_is\_dependent ($boolean)

Indicates whether or not the second table in the foreign key is dependent on the other (i.e. whether the 'to' table is dependent on the 'from' table).

### id

Returns a string uniquely identifying the foreign key.

### is\_same\_relationship\_as ($fk)

Given a foreign key object, this returns true if the two objects represent the same relationship.  However, the two objects may represent the same relationship from different table's points of view.

### comment

Returns the comment associated with the foreign key object, if any.

### set\_comment ($comment)

Sets the comment for the foreign key object.

## AUTHOR

Dave Rolsky, \<autarch@urth.org\>
