Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Custom core files for enable composite primary keys in your CakePHP 2.x project
PHP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
Lib/Model
LICENSE
README.md

README.md

Composite Primary Keys in CakePHP 2.x

You need first

  • CakePHP 2.x project

Note

This is not a good pratice for database modeling, so, the recommended is use just a simple primary key:

    -- in mysql
    id int not null primary key

    -- in postgresql
    id serial primary key

Instructions

  • Download (not clone) this repostory with zip (link at right).
  • Extract the zip file in a temp folder (out of your CakePHP project)
  • Open the folder created and copy the folder Lib. This folder contain all files you need.
  • Paste in your app folder for your Project, like that: /your-project/app/
  • Now you need add some code in your mode with composite primary keys:
    public $primaryKey = false;
    public $compositePrimaryKey = array('key_one', 'key_two', 'key..........');

Done!

Model id

Now, if you do $this->YOUR_MODEL->id, you get an array like that:

    'id' => array(
        'key_one' => value_of_key,
        'key_two' => value_of_key,
        'key_three' => value_of_key
    )

You wanna help? Send a pull request!

Sorry for my english, and of course, THANKS SO MUCH!

Something went wrong with that request. Please try again.