Smutty


Smutty.Smutty_Model

Class Smutty_Model

Smutty_Object
|
+--Smutty_Model

public class Smutty_Model
extends Smutty_Object

this is the base class for all Smutty models. it provides many methods and utilities which (hopefully) make using models the joy it should be.

/


Field Summary
mixed

$hasMany

allows specifying dependent models by their name.

mixed

$hasOne

mixed

$hasRelation

mixed

$rss

enable rss output for this model */

mixed

$tableName

the name of this models table, defaults to false so it will be

mixed

$validate

this property should be used to specify how data is to

Constructor Summary

Smutty_Model()

constructor

Method Summary
boolean

delete()

deletes the current model from the database

static nothing

deleteWhere(String class, array params)

this method allows deleting of multiple records

boolean

exists(String id)

determines if a record with the specified id currently exists in this models table

static array

fetchAll(String class, String order, array params, mixed whereSql, array joins, String limit)

returns all the records for this model

nothing

fill()

this method tries to automatically fill a model with data that has been passed to the application.

static Smutty_Model

find(String class, String id, String field)

this function allows searching for a record by it's unique id.

array

getErrors()

returns an array containing any errors that were encountered the last time the model was validated.

static array

getFields(String class)

returns an array of this models fields and their types

private static void

getJoinSql(String fromAlias, String joins)

returns the sql to do a join to the dot seperated list of models specified.

static int

getTotal(String class)

returns the total number of records for the model

boolean

isValid()

this function checks if the models data is currently in a valid state to be saved.

boolean

save()

this function saves a models data, it returns a boolean indicating if the save went ahead ok or not.

Field Detail

hasMany

public mixed $hasMany = ''

allows specifying dependent models by their name. the related


hasOne

public mixed $hasOne = ''

hasRelation

public mixed $hasRelation = ''

rss

public mixed $rss = ''

enable rss output for this model */


tableName

public mixed $tableName = false

the name of this models table, defaults to false so it will be


validate

public mixed $validate = array()

this property should be used to specify how data is to


Constructor Detail

Smutty_Model

public Smutty_Model()

constructor


Method Detail

delete

public boolean delete()

deletes the current model from the database

Returns:
if delete succeeded
Go to code

deleteWhere

public static nothing deleteWhere(String class, array params)

this method allows deleting of multiple records

Parameters:
class - the class to delete for
params - assoc array of where params
Go to code

exists

public boolean exists(String id)

determines if a record with the specified id currently exists in this models table

Parameters:
id - the id to search for
Returns:
indicates if id exists
Go to code

fetchAll

public static array fetchAll(String class, String order, array params, mixed whereSql, array joins, String limit)

returns all the records for this model

Parameters:
class - the class to search
order - order the results by eg. "field:desc"
params - name/value pairs for fields to match
limit - how to limit results eg. "start:count"
joins - array or string of model joins to make
Returns:
Model objects
Go to code

fill

public nothing fill()

this method tries to automatically fill a model with data that has been passed to the application.

Go to code

find

public static Smutty_Model find(String class, String id, String field)

this function allows searching for a record by it's unique id. if it is found then an instance of it's model object will be returned, otherwise you'll get false.

Parameters:
class - the model class to search
id - the id to find
field - the field to find on (default='id')
Returns:
the model found
Go to code

getErrors

public array getErrors()

returns an array containing any errors that were encountered the last time the model was validated.

Returns:
array of error strings
Go to code

getFields

public static array getFields(String class)

returns an array of this models fields and their types

Parameters:
class - the class to fetch fields for
Returns:
fields for this model
Go to code

getJoinSql

private static void getJoinSql(String fromAlias, String joins)

returns the sql to do a join to the dot seperated list of models specified. an inner join is used.

eg. getJoinSql( 'Post', 'User.UserType' );

Parameters:
fromAlias - the alias to join from
joins - dot seperated string of models
Go to code

getTotal

public static int getTotal(String class)

returns the total number of records for the model

Parameters:
class - class to fetch for
Returns:
total records
Go to code

isValid

public boolean isValid()

this function checks if the models data is currently in a valid state to be saved. this means that all validation criteria that have been specified need to be met.

errors are stored in $this->errors and can be accessed by using the $this->getErrors() function.

Returns:
indicates validity
Go to code

save

public boolean save()

this function saves a models data, it returns a boolean indicating if the save went ahead ok or not.

Returns:
if save succeeded
Go to code

Smutty