Skip to content

Commit

Permalink
starts using Model Meta information in Queryset
Browse files Browse the repository at this point in the history
  • Loading branch information
eddmash committed Mar 3, 2016
1 parent b9525b7 commit 4bfb811
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 83 deletions.
39 changes: 16 additions & 23 deletions Base_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ public function __construct(){
* @return mixed
*/
public function __call($method, $args){
// ToDo what if the object is already created

// create a Queryset if method is class and is present in Queryset
if (!method_exists($this, $method) &&
Expand Down Expand Up @@ -287,6 +286,22 @@ public function queryset(){
return $this->_get_queryset();
}

/**
* Returns the name of the primary key column
* @return string
*/
public function primary_key(){
$table_columns = $this->meta();

$primary_key_column = NULL;
foreach ($table_columns as $col) :
if($col->primary_key):
$primary_key_column = $col->name;
endif;
endforeach;

return $primary_key_column;
}



Expand Down Expand Up @@ -397,28 +412,6 @@ public function set_dates(){
}
}

/**
* ToDo remove from base model
* @ignore
* @param bool $owner_field
* @return bool
*/
public function is_owner($owner_field=FALSE){
$status = FALSE;
$user_id = $this->auth->user->id;

if($owner_field==False && $this->user_id == $user_id){
$status = TRUE;
}

if($owner_field!=False && $this->{$owner_field} == $user_id){
$status = TRUE;
}

return $status;
}





Expand Down
4 changes: 4 additions & 0 deletions OrmErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@
*/
class OrmErrors extends ErrorException{}

/**
* Raised by Orm
* Class TypeError
*/
class TypeError extends OrmErrors{}
Loading

0 comments on commit 4bfb811

Please sign in to comment.