mysql sharding, Horizontal sharding table

because one table have many records.

i spilt the table as month (date).

one month one table.

such as table named notes.

tables is:

notes notes201303 notes201304

in model class i defined the model class like this:

class Notes extends Model {
    public function initialize () {.....}
    public function getSource() {
        return 'pre_notes';

now,i can't use the model class in project . because the model method getSource defined the db table.

how can define the model db table dynamic? or have other method resloved the question ? except use the Phalcon\Db


I realized that the getSource method is called everytime before a query is issued. If you could determine the required table by time of the call you could just return the propper tablename.

Take a look here: in the Vertical/Horizontal Sharding Improvements section). In the selectReadConnection method you might set a flag or name for the source and return it in the getSource method. I think this might work if the table meta data does not change. Just an idea, dont know if it works or has side effects.


michaelkrone , thank you

in my old thread

i asked a question about selectreadconnection . but this method return a connection, not a table.

now i decide don't split a table to many table, i used the mysql partitioning to resolved this question

@netstu, u can use $this->setSource()

class Notes extends Model {
    public function initialize () {
       //check date


@Marcio Paivam, i can't understand your mean.

what different in model's class use setSource in initialize or use getSource?

they should be the same


Marcio suggests nearly the same procedure as I did: If you know (or can somehow compute) wich date is requested inside the initialize method (or any other method Phalcon calls automaticly before fetching the data, selectReadConnection etc.) you can set the source to use. You do not need a getSource implementation then.