Model class
This class is the main Model class
Example
class User extends Model {
protected $table = 'user';
protected $primaryKey = 'id';
protected $fillable = ["fullName", "email"];
}
$user = new User();
$user->fullName = "John Doe";
$user->email = "johndoe@example.com";
$user->save();
$foundUser = User::find($user->getPrimaryValue());
$user2 = User::where("fullName", "John Doe")->limit(1)->orderBy('id')->exec();
package |
Default |
---|
_create() : void
Create new Model, Also does INSERT into $table
_update() : void
Update Model, Also does UPDATE into $table
all() : \TinyORM\Model
array2obj(array $arr, mixed $obj) : \TinyORM\Model
create(array $data) : \TinyORM\Model
Create new Model
Example
User::Create([
'name' => 'John Doe'
]);
array
\TinyORM\Model
delete() : void
Delete this model from database
Example
$user = User::find('2344');
$user->delete();
exec() : array
Execute the SELECT operation on $this->query
Example
User::where('name', '=', 'John Doe')->exec();
array
find(string $id) : \TinyORM\Model
Find a Modal by its primary Key
Example
// Find user with id = '1234'
$user = User::find('1234');
string
\TinyORM\Model
getPrimaryKey() : string
Returns the primary key
string
getPrimaryValue() : string
Returns the value of primary key
string
getSQLQuery() : string
Return the SQL query
Example
echo User::where('name', '=', 'John Doe')->getSQLQuery();
// Returns "SELECT FROM User WHERE name = 'John Doe'"
string
getTable() : string
Returns the table name for this Model
string
limit(integer $limit) : \TinyORM\Model
Add LIMIT in this SELECT operation
Example
User::where('name', '=', 'John Doe')->limit(1)->exec();
integer
\TinyORM\Model
offset(integer $offset) : \TinyORM\Model
Add OFFSET in this SELECT operation
Example
User::where('name', '=', 'John Doe')->offset(10)->exec();
integer
\TinyORM\Model
orderBy(string $column, string $dir = 'ASC') : \TinyORM\Model
Add ORDER BY in this SELECT operation
Example
User::where('name', '=', 'John Doe')->orderBy('name', 'DESC')->exec();
string
string
\TinyORM\Model
save() : void
This methods does create() or update() depending upon if the primaryValue
Example
$user = new User();
$user->name = 'John Doe';
$user->save();
where(string $column, string $operator, string $value = '') : \TinyORM\Model
Add where condition in this SELECT operation
Example
User::where('name', '=', 'John Doe')->exec();
string
Name of the database table column
string
SQL operator =, <, >, <> etc
string
Value to the compared with the value in $column and $operator
\TinyORM\Model
table : string
var |
Database table |
---|
string
primaryKey : string
var |
Primary column name |
---|
string
fillable : array
var |
Table columns |
---|
array