pomm-project / ModelManager

Model Manager for the Pomm database framework.
MIT License
66 stars 27 forks source link

Empty primary key #20

Closed tlode closed 9 years ago

tlode commented 9 years ago

If a RowStructure defines an empty primary key, like

        $this
            ->setRelation('foo')
            ->setPrimaryKey([])
            ->addField('foo_id', 'int4')
            etc..

then WriteQueries::updateOne and WriteQueries::deleteOne build a query which will update or delete all rows!

This is not a bug, but it should not be possible to define an empty primary key in a model.

The above code is the result of using the CLI code generator on a relation which uses a UNIQUE key instead of a PRIMARY KEY. Maybe the CLI code generator could throw a warning in such a case?

chanmix51 commented 9 years ago

Even if it is good practice to define a primary key for each relation, I came across cases when there are none. In this case, it is still life saving to rely on Pomm and its ability to perform basic operations. Of course, methods like updateOne(), deleteByPk() must throw an exception when primary key is empty.

Opinions welcome.

stood commented 9 years ago

https://github.com/pomm-project/ModelManager/pull/24