Table of Contents
ObjectPtr field is a unique Valentina Database Model feature. ObjectPtr allows to set M:1 and 1:1 relationship between the two Tables. As only you have created an ObjectPtr field you have established also the Link between two tables.
This kind of Link is similar to both FOREIGN KEY of Relational Model and to direct pointer of Network Model.
This Field keeps values of the RecID field of parent/target Table. So its type is ULONG and the size is 4 bytes.
ObjectPtr can be used as both FIELD and LINK.
You should check ObjectPtr Link page to read about ObjectPtr as a LINK.
Comparison to Relational Model
Let's look on Relational Model and how we define a relation between two tables using Primary Key (PK) and Foreign Key (FK).
Let we have:
- Table T1 with ID field.
- Table T2, which refers to T1 with the help of FK constraint t1_id.
To define this constraint, we have to specify:
- The name of the target table.
- Field(s) of the Target table which are its Primary Key.
- Constraint name.
- Action ON DELETE.
- Action ON UPDATE.
CREATE TABLE T1( id ULONG autoincrement, f1 INT ... ); CREATE TABLE T2( id ULONG autoincrement, t1_id ULONG, CONSTRAINT FK_T2_T1 REFERENCES T1(ID) ON DELETE CASCADE ON UPDATE CASCADE )
Working with ObjectPtr field, we have to define less details, because:
- There is no sense mention RecID, it is always the same.
- There is no sense in the ON UPDATE action for ObjectPtr, since RecID never changes its value.
CREATE TABLE T1( f1 INT ... ); CREATE TABLE T2( t1Ptr ObjectPtr CONSTRAINT linkT2T1 REFERENCES T1 ON DELETE CASCADE )
Comparison to Navigational Model
In the Navigational Model developer operates using special API to link two records of different objects. Important here is:
- Developer just asks database engine to link the current record of T1 to the current record of T2.
- Value of reference to another record is some internal value.
- Developer do not see this internal value.
- Developer cannot specify its type.
- Developer cannot change this value.
- By reference db engine can jump directly to pointed record.
Now lets look on RecID and ObjectPtr pair, which together give us ObjectPtr-link.
- RecID value is internal value.
- Developer can see value of RecID, but cannot change it.
- Developer knows the type of RecID values (ULONG), but cannot change it.
- By RecID value vdb engine can jump directly to pointed record.