Feature Request #3697

Late static binding on table dependent model settings

Added by Kemal Delalic almost 4 years ago. Updated 11 months ago.

Status:NewStart date:02/05/2011
Priority:LowDue date:
Assignee:Lorenzo Pisani% Done:

0%

Category:-
Target version:Kohana v3.x - Unscheduled
Resolution: Points:

Description

There are many properties in the model which should be static, there is no need to have them in each object instance.


Related issues

Related to ORM - Bug Report #4333: Speed up ORM::_initialize() Closed 11/12/2011
Blocks ORM - Bug Report #3866: Static method for checking if a record exists New 03/18/2011

History

#1 Updated by Kiall Mac Innes almost 4 years ago

  • Project changed from Kohana v3.x to ORM
  • Category deleted (Modules:ORM)

#2 Updated by Lorenzo Pisani over 3 years ago

  • Target version changed from v3.2.0 to v3.3.0

We can't require PHP 5.3 in 3.2.x yet. This needs to be re-evaluated for 3.3.x

#3 Updated by Lorenzo Pisani over 3 years ago

  • Assignee set to Lorenzo Pisani

#4 Updated by David Farnan about 3 years ago

I would like to second this. I was actually looking for a way to create an inherited static "exists" function for my models which would use the primary key as input and return if the row exists for validation purposes. It seems looking at the code that this is a fairly simple change inside ORM since the model properties are already protected. I'm curious what the performance implications are.

#5 Updated by Jeremy Bush almost 3 years ago

  • Target version changed from v3.3.0 to Unscheduled

#6 Updated by Kemal Delalic 11 months ago

Can we schedule this for 3.4? I'm willing to work on it in January

#7 Updated by Lorenzo Pisani 11 months ago

I only want to schedule things for 3.4 that are urgent (in a few different ways) but feel free to work on this and send a PR. I will definitely merge it into 3.4.0 if you do the work needed.

#8 Updated by Kemal Delalic 11 months ago

Ok here is what I think about making static;

    protected static $_column_cache = array();
    protected static $_initialized = FALSE;
    protected static $_db = NULL;
    protected static $_db_group = NULL;
    protected static $_has_one = array();
    protected static $_belongs_to = array();
    protected static $_has_many = array();
    protected static $_load_with = array();
    protected static $_foreign_key_suffix = '_id';
    protected static $_object_name;
    protected static $_object_plural;
    protected static $_table_name;
    protected static $_table_columns;
    protected static $_sorting;
    protected static $_updated_column = NULL;
    protected static $_created_column = NULL;
    protected static $_serialize_columns = array();
    protected static $_primary_key = 'id';
    protected static $_table_names_plural = TRUE;
    protected static $_reload_on_wakeup = TRUE;
    protected static $_errors_filename = NULL;

You'll notice that a few of these are already static. Do we need to enable 2 objects of the same class using different databases or something similar? All of these look quite straightforward otherwise

#9 Updated by Kemal Delalic 11 months ago

And this is what every instance of ORM would still contain;

protected $_validation = NULL;
protected $_object = array();
protected $_changed = array();
protected $_original_values = array();
protected $_related = array();
protected $_valid = FALSE;
protected $_loaded = FALSE;
protected $_saved = FALSE;
protected $_primary_key_value;
protected $_db_applied = array();
protected $_db_pending = array();
protected $_db_reset = TRUE;
protected $_db_builder;
protected $_with_applied = array();
protected $_cast_data = array();

I have done the rewrite partially on localhost already and using it for a pet project, dumping ORM objects doesn't hurt your eyes nearly as much as it used to :)

#10 Updated by Kemal Delalic 11 months ago

Also, these might be in a separate class;

protected $_db_applied = array();
protected $_db_pending = array();
protected $_db_reset = TRUE;
protected $_db_builder;
protected $_with_applied = array();

Maybe `ORM_Query_Builder`?

Also available in: Atom PDF