Вопрос

I'm using peewee as my ORM for mysql DB. I have 3 tables in my scheme, one for devices, one for apps and one for results per device per tester app and tested app. the APPS table looks like:

package name | version name | version code |apk name

the 3 first columns are my primary key since i want every revision in my table and i want it to be easy to filter apps according to certain version code (version code is incremented with revisions in git\svn while version name represents the version itself as taken from the development branch). My problem starts when i want to have the APPS table as a reference table for my TESTS table, meaning each test refers to the APPS twice, once for the tester and once for the tested app. I'm not sure if it's such a good idea to have a 3 fields foreign key (which makes it 6!) in my TESTS table.

Any good solution for that ? I tried adding _ID field with auto increment as a 'KEY' so i'll have a numeric single field to access, but the ORM doesn't really supports it and i'm kinda gritting my teeth trying to pull this off.

Is my Db just organized bad or i need to simply replace ORM ? i think that without the ORM i would probably pull it off pretty easily...

Это было полезно?

Решение

Options:

  1. Define an auto incremented primary key in the APPS table.
  2. Define composite unique key in APPS table on pkg, ver, and vcode columns.
  3. Use the primary key value of this table as FK reference in child table.

Другие советы

This is a very late answer, but I want to contribute the code for telling peewee about a composite key, something like the following. When this construct is used, Peewee does NOT add an "id" column to the table:

class SillyTable(peewee.Model):
    field1 = peewee.IntegerField(null=False)
    field2 = peewee.IntegerField(null=False)
    # Composite key, no "id" column needed.
    class Meta:
        primary_key = peewee.CompositeKey('field1','field2')

I'm using peewee v2.6.3 and PyMySQL v0.6.3 to access MySQL.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top