<?php
/**
*
* Configuration file for OR mapping.
*
* This file is big because it is annotated to be used as help and example.
*
*
* IMPORTANT NOTE :
* If you are using PHPersistence in a PHP5 environment, you can give the real case for the class names.
* For prior PHP versions, CLASSNAMES HAVE TO BE GIVEN LOWERCASED in this config file!
*
* Possible cascade values :
* cascade="all|none|save-update|delete"
*
*
**/
/**
* Table Mapping : maps classes to the corresponding tables in the database
* $tableMapping["CLASS_NAME"] = "TABLE_NAME";
*/
$tableMapping["user"] = "users";
$tableMapping["product"] = "products";
$tableMapping["wine"] = "wines";
$tableMapping["shirt"] = "shirts";
$tableMapping["cart"] = "carts";
/**
* Field Mapping : maps the members of a class to the fields of a table
*
*/
$fieldMapping["user"] = array(
"id" => "id",
"name" => "name",
"firstname" => "firstname",
"mail" => "mail"
);
$fieldMapping["product"] = array(
"id" => "id",
"name" => "name",
"description" => "description",
"price" => "price"
);
$fieldMapping["wine"] = array(
"id" => "id",
"millesime" => "millesime",
"AOC" => "aoc"
);
$fieldMapping["shirt"] = array(
"id" => "id",
"size" => "size",
"color" => "color"
);
$fieldMapping["cart"] = array(
"id" => "id",
"date" => "date"
);
/**
* Primary key mapping
*
* $primaryKeyMapping["CLASS_NAME"] = array(
* 0 => member name de la classe
* 1 => field name in the table
*
*/
$primaryKeyMapping["user"] = array(
0 => "id",
1 =>"id");
$primaryKeyMapping["product"] = array(
0 => "id",
1 =>"id");
$primaryKeyMapping["shirt"] = array(
0 => "id",
1 =>"id");
$primaryKeyMapping["wine"] = array(
0 => "id",
1 =>"id");
$primaryKeyMapping["cart"] = array(
0 => "id",
1 =>"id");
/**
* Many-to-One mapping
*
* The class "A" contains one instance of class "B"
*
* 2 tables are used : table for class "A" and table for class "B".
* The table for class "A" contains the foreign key of "B".
*
* "cascade" indicates what to do with "B" if class "A" is updated or deleted.
*
* Possible cascade values and meaning :
* "none" : "B" is ignored
* "save-update" : "B" is saved and updated each time "A" is saved or updated (but not deleted)
* "delete" : "B" is deleted when "A" is deleted
* "all" : is "save-update" and "delete"
*
*
* See example application and comments for more details
*
*/
$manyToOneMapping["cart"] = array( // name of class "A" (lowercased)
"user" => array( // in class "A", the member name that will hold the instance of "B"
"class" => "User", // name of class "B" (lowercased)
"column" => "user", // in table of "A", the column that will hold the foreign key, the "B" primary key
"cascade" => "save-update" // cascade
)
);
/**
* Element Mapping
*
* The class "A" has a member "b" that is an array of primitive data (string, integer, etc.)
* The data from "b" is stored in a dedicated table, containing a foreign key of "A".
*
* Cascade is always implicitely to "all".
*
* See example application if the explanations seem not clear.
*/
$elementMapping["user"] = array( // name of class "A" (lowercased)
"telephones" => array( // in class "A", the member name that will hold the array "b"
"table" => "users_telephones", // table name of "b"
"keyname" => "id", // primary key of class "A"
"keycolumn" => "id_user", // in the table of "b", the column name of the external key. This field will make the join with the class "A" primary key.
"elementcolumn" => "telephone" // in the table of "b", the column name of the data
)
);
/**
*
* Many-to-many Mapping
*
* n-n relationship.
*
* The class "A" contains an array of class "B" objects
*
* 3 tables are involved : table for "A", table for "B" and separate "link" table storing the primary key correspondance.
*
* "cascade" indicates what to do with "B" if class "A" is updated or deleted.
*
* Possible cascade values and meaning :
* "none" : "B" is ignored
* "save-update" : "B" is saved and updated each time "A" is saved or updated (but not deleted)
* "delete" : "B" is deleted when "A" is deleted
* "all" : is "save-update" and "delete"
*
*/
$manyToManyMapping["cart"] = array( // name of class "A" (lowercased)
"products" => array( // in class "A", the member name that will hold the array of objects of "B"
"class" => "Product", // name of class "A" (not lowercased)
"table" => "cart_products", // name of the "link" table
"keyname" => "id", // member name of primary key of class "A"
"keycolumn" => "id_cart", // in the "link" table foreign key column for class "A"
"manytomanycolumn" => "id_product", // in the "link" table foreign key column for class "B"
"cascade" => "none" // cascade
)
);
/**
* Inhibit nextId
*
* phpersistence uses by default a mechanism to generate an id for primary keys when an object is saved.
* This is currently the PEAR::DB mechanism.
*
* If phpersistence is deployed in an existing environment with another mechanism,
* those mechanisms may confilict and lead to not unique ids.
*
* In this case you can specify which classes ids should not use the phpersistence id generation mechanism.
*
* Indicate the names of the classes.
*/
$inhibitNextId = array('class_1', 'class_2');
/**
* phpersistence uses by default a mechanism to generate an id for primary keys when an object is saved.
* This is currently the PEAR::DB mechanism.
*
* If you want to use the MySQL Auto-increment to generate primary keys, specify here
* which classes should not use the phpersistence id generation mechanism, and should get the keys
* from MySQL Auto-increment.
*
* This is recommanded only if you have good reason (for example your application is already running)
* because the phpersistence mechanism (using PEAR::DB nextId) is more generic and database independent.
*
* Note : you don't need to specify $inhibitNextId for the given classes
*
* Indicate the names of the classes.
*/
$useMySQLLastInsertId = array('class_3', 'class_4');
?>