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

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

Comments

Projects
None yet
2 participants
@EkoSolutionsBe
Contributor

EkoSolutionsBe commented Dec 4, 2013

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

This comment has been minimized.

Show comment
Hide comment
@EkoSolutionsBe

EkoSolutionsBe Dec 9, 2013

Contributor

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.

Contributor

EkoSolutionsBe commented Dec 9, 2013

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

This comment has been minimized.

Show comment
Hide comment
@besstiolle

besstiolle Jul 2, 2014

Owner

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

Owner

besstiolle commented Jul 2, 2014

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

@besstiolle besstiolle closed this Jul 2, 2014

@EkoSolutionsBe EkoSolutionsBe removed their assignment Aug 19, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment