Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

[Entity][Field] Manage the "compouned key" system of Mysql #4

Closed
EkoSolutionsBe opened this issue Dec 4, 2013 · 2 comments
Closed

Comments

@EkoSolutionsBe
Copy link
Contributor

Actually, Orm doesn't allow us to use compouned keys.

Current code consider PK as a single field.

I'd prefer Entity::pk to be an array (or single value OR array, managed by "is_array" inside the code, but easier is to have array type).

As getPk() doesn't have to return "the name of the field that is PK", but "all fields making part of the PK".

    protected function add(Field $newField) {
        $this->fields[$newField->getName()] = $newField;

        //Add a sequence on the keys
        if($newField->isPrimaryKEY())
        {
            if($this->pk != null)
                throw new IllegalConfigurationException("Orm doesn't support multi-Primary-Key into the Entity ".$this->name);

            $this->pk = $newField->getName();
            $this->seqname = $this->dbname.Entity::$_CONST_SEQ;
        }
    }

must change to something like:

    protected function add(Field $newField) {
        $this->fields[$newField->getName()] = $newField;

        //Add a sequence on the keys
        if($newField->isPrimaryKEY())
        {
            $this->addPK($newField->getName());
            $this->seqname = $this->dbname.Entity::$_CONST_SEQ;
        }
    }

It should be nice to have helper managing this logic:

  • static entity cache of PK string for update/delete WHERE clause : " WHERE field1 = ? AND field2 = ? "

So that Core::deleteByIds(), Core::updateEntity(), Core::findByIds() can use it.

$queryUpdate = 'UPDATE '.$entityParam->getDbname().' SET '.$str.$where;

become

$queryUpdate = 'UPDATE '.$entityParam->getDbname().' SET '.$str.$entityParam->getPKWhere();

Entity::getPKWhere() manage so internal cache avoiding function calls.

@ghost ghost assigned EkoSolutionsBe Dec 6, 2013
@EkoSolutionsBe
Copy link
Contributor Author

As discussed, we'll use for this use a master "PrimaryKey" class that will be iinherited.

So that MyEntity will be associated to a MyEntityId extends PrimaryKey.

PrimaryKey will provide services like check on each values.

findById() signature will move to findById(&Entity $myEntity, mixed $id)

With $id type either string (main use) or PrimaryKey.

@besstiolle
Copy link
Owner

implementation on the branch composite primary key is over. the tests with a real project are in progress.

@EkoSolutionsBe EkoSolutionsBe removed their assignment Aug 19, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants