Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing private -> protected for extensibility #519

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions lib/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,35 +85,35 @@ class Model
*
* @var array
*/
private $attributes = array();
protected $attributes = array();

/**
* Flag whether or not this model's attributes have been modified since it will either be null or an array of column_names that have been modified
*
* @var array
*/
private $__dirty = null;
protected $__dirty = null;

/**
* Flag that determines of this model can have a writer method invoked such as: save/update/insert/delete
*
* @var boolean
*/
private $__readonly = false;
protected $__readonly = false;

/**
* Array of relationship objects as model_attribute_name => relationship
*
* @var array
*/
private $__relationships = array();
protected $__relationships = array();

/**
* Flag that determines if a call to save() should issue an insert or an update sql statement
*
* @var boolean
*/
private $__new_record = true;
protected $__new_record = true;

/**
* Set to the name of the connection this {@link Model} should use.
Expand Down Expand Up @@ -671,7 +671,7 @@ public static function table_name()
* @param array $delegate An array containing delegate data
* @return delegated attribute name or null
*/
private function is_delegated($name, &$delegate)
protected function is_delegated($name, &$delegate)
{
if ($delegate['prefix'] != '')
$name = substr($name,strlen($delegate['prefix'])+1);
Expand Down Expand Up @@ -708,7 +708,7 @@ public function is_new_record()
* @throws \ActiveRecord\ReadOnlyException
* @param string $method_name Name of method that was invoked on model for exception message
*/
private function verify_not_readonly($method_name)
protected function verify_not_readonly($method_name)
{
if ($this->is_readonly())
throw new ReadOnlyException(get_class($this), $method_name);
Expand Down Expand Up @@ -797,7 +797,7 @@ public function save($validate=true)
* @param boolean $validate Set to true or false depending on if you want the validators to run or not
* @return boolean True if the model was saved to the database otherwise false
*/
private function insert($validate=true)
protected function insert($validate=true)
{
$this->verify_not_readonly('insert');

Expand Down Expand Up @@ -858,7 +858,7 @@ private function insert($validate=true)
* @param boolean $validate Set to true or false depending on if you want the validators to run or not
* @return boolean True if the model was saved to the database otherwise false
*/
private function update($validate=true)
protected function update($validate=true)
{
$this->verify_not_readonly('update');

Expand Down Expand Up @@ -1077,7 +1077,7 @@ public function values_for($attribute_names)
*
* @return boolean True if passed validators otherwise false
*/
private function _validate()
protected function _validate()
{
require_once 'Validations.php';

Expand Down Expand Up @@ -1195,7 +1195,7 @@ public function set_attributes(array $attributes)
* @param array $attributes An array in the form array(name => value, ...)
* @param boolean $guard_attributes Flag of whether or not protected/non-accessible attributes should be guarded
*/
private function set_attributes_via_mass_assignment(array &$attributes, $guard_attributes)
protected function set_attributes_via_mass_assignment(array &$attributes, $guard_attributes)
{
//access uninflected columns since that is what we would have in result set
$table = static::table();
Expand Down Expand Up @@ -1861,7 +1861,7 @@ public function to_array(array $options=array())
* @param array $options Options array for the serializer
* @return string Serialized representation of the model
*/
private function serialize($type, $options)
protected function serialize($type, $options)
{
require_once 'Serialization.php';
$class = "ActiveRecord\\{$type}Serializer";
Expand All @@ -1876,7 +1876,7 @@ private function serialize($type, $options)
* @param boolean $must_exist Set to true to raise an exception if the callback does not exist.
* @return boolean True if invoked or null if not
*/
private function invoke_callback($method_name, $must_exist=true)
protected function invoke_callback($method_name, $must_exist=true)
{
return static::table()->callback->invoke($this,$method_name,$must_exist);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ protected function set_class_name($class_name)
if (!has_absolute_namespace($class_name) && isset($this->options['namespace'])) {
$class_name = $this->options['namespace'].'\\'.$class_name;
}

$reflection = Reflections::instance()->add($class_name)->get($class_name);

if (!$reflection->isSubClassOf('ActiveRecord\\Model'))
Expand Down Expand Up @@ -505,7 +505,7 @@ public function load(Model $model)
$fk = $this->foreign_key;

$this->set_keys($this->get_table()->class->getName(), true);

$class = $this->class_name;
$relation = $class::table()->get_relationship($this->through);
$through_table = $relation->get_table();
Expand Down Expand Up @@ -602,7 +602,7 @@ public function create_association(Model $model, $attributes=array(), $guard_att
public function load_eagerly($models=array(), $attributes=array(), $includes, Table $table)
{
$this->set_keys($table->class->name);
$this->query_and_attach_related_models_eagerly($table,$models,$attributes,$includes,$this->foreign_key, $table->pk);
$this->query_and_attach_related_models_eagerly($table,$models,$attributes,$includes,$this->foreign_key, $this->primary_key);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benmcmath are you able to explain the purpose this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To use the primary key on the association, and not the table. Primary key can be explicitly set in the association, and that key might be different than the table's primary key. I believe if the association doesn't have a primary key, the table's primary key is used.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ding ding: this rings a bell now. @koenpunt is right, we'll want a test for this.

}
}

Expand Down
28 changes: 14 additions & 14 deletions lib/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
class Table
{
private static $cache = array();
protected static $cache = array();

public $class;
public $conn;
Expand Down Expand Up @@ -60,7 +60,7 @@ class Table
/**
* List of relationships for this table.
*/
private $relationships = array();
protected $relationships = array();

public static function load($model_class_name)
{
Expand Down Expand Up @@ -276,7 +276,7 @@ public function find_by_sql($sql, $values=null, $readonly=false, $includes=null)
* @param $includes array eager load directives
* @return void
*/
private function execute_eager_load($models=array(), $attrs=array(), $includes=array())
protected function execute_eager_load($models=array(), $attrs=array(), $includes=array())
{
if (!is_array($includes))
$includes = array($includes);
Expand Down Expand Up @@ -386,12 +386,12 @@ public function delete($data)
*
* @param Relationship $relationship a Relationship object
*/
private function add_relationship($relationship)
protected function add_relationship($relationship)
{
$this->relationships[$relationship->attribute_name] = $relationship;
}

private function get_meta_data()
protected function get_meta_data()
{
// as more adapters are added probably want to do this a better way
// than using instanceof but gud enuff for now
Expand All @@ -409,7 +409,7 @@ private function get_meta_data()
* @param $map array Hash of used_name => real_name
* @return array Array with any aliases replaced with their read field name
*/
private function map_names(&$hash, &$map)
protected function map_names(&$hash, &$map)
{
$ret = array();

Expand All @@ -423,7 +423,7 @@ private function map_names(&$hash, &$map)
return $ret;
}

private function &process_data($hash)
protected function &process_data($hash)
{
if (!$hash)
return $hash;
Expand All @@ -443,7 +443,7 @@ private function &process_data($hash)
return $hash;
}

private function set_primary_key()
protected function set_primary_key()
{
if (($pk = $this->class->getStaticPropertyValue('pk',null)) || ($pk = $this->class->getStaticPropertyValue('primary_key',null)))
$this->pk = is_array($pk) ? $pk : array($pk);
Expand All @@ -459,7 +459,7 @@ private function set_primary_key()
}
}

private function set_table_name()
protected function set_table_name()
{
if (($table = $this->class->getStaticPropertyValue('table',null)) || ($table = $this->class->getStaticPropertyValue('table_name',null)))
$this->table = $table;
Expand All @@ -477,7 +477,7 @@ private function set_table_name()
$this->db_name = $db;
}

private function set_cache()
protected function set_cache()
{
if (!Cache::$adapter)
return;
Expand All @@ -494,7 +494,7 @@ private function set_cache()
}
}

private function set_sequence_name()
protected function set_sequence_name()
{
if (!$this->conn->supports_sequences())
return;
Expand All @@ -503,7 +503,7 @@ private function set_sequence_name()
$this->sequence = $this->conn->get_sequence_name($this->table,$this->pk[0]);
}

private function set_associations()
protected function set_associations()
{
require_once __DIR__ . '/Relationship.php';
$namespace = $this->class->getNamespaceName();
Expand Down Expand Up @@ -551,7 +551,7 @@ private function set_associations()
* 'to' => 'delegate_to_relationship',
* 'prefix' => 'prefix')
*/
private function set_delegates()
protected function set_delegates()
{
$delegates = $this->class->getStaticPropertyValue('delegate',array());
$new = array();
Expand Down Expand Up @@ -591,7 +591,7 @@ private function set_delegates()
/**
* @deprecated Model.php now checks for get|set_ methods via method_exists so there is no need for declaring static g|setters.
*/
private function set_setters_and_getters()
protected function set_setters_and_getters()
{
$getters = $this->class->getStaticPropertyValue('getters', array());
$setters = $this->class->getStaticPropertyValue('setters', array());
Expand Down