This repository was archived by the owner on May 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Nick Barham edited this page Dec 21, 2017
·
16 revisions
$ composer require brokencube\automatorm:^6.0<?php
// init.php
use Automatorm\DataLayer\Database\Connection;
use Automatorm\Orm\Schema;
// Get db connection
$connection = Connection::register($pdo);
// Get db schema for the ORM and assign to 'models' namespace
Schema::generate($connection, 'models'); <?php
// Create a class that is linked to a table named "blog"
namespace models {
Class Blog extends Automatorm\Orm\Model {}
}
// Find a table row based on a simple where clause
// Equivalent: Select * from blog where title = 'My First Entry';
$blog = Blog::find(['title' => 'My First Entry']);
echo $blog->id; // Prints "1"
echo $blog->title; // Prints "My First Entry"Automatorm is designed to work on existing databases, however it assumes some conventions for all functionality to function correctly:
- Table names must be lowercase and underscore_case (The ORM will automatically convert these to TitleCase for matching to class names)
- All tables (excepting M-M junction tables) must have an integer 'id' column. It is recommended you use this as the primary key. (I aim to lift this limitation in the future)
- "Junction" / "M-M join" tables should contain an equal number of columns and foreign keys (and no id column)
- All columns that are foreign keys should end in '_id'
See Database for more details
Many of the examples in this wiki below will be based around this small example database:

See ORM for more details
