Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

EkoSolutionsBe opened this issue Dec 4, 2013 · 2 comments

Comments

@EkoSolutionsBe
Copy link
Contributor

@EkoSolutionsBe 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
Copy link
Contributor Author

@EkoSolutionsBe 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
Copy link
Owner

@besstiolle 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants