Cannot create composite_index(classtype, somefield) #98

socketpair opened this Issue Nov 5, 2014 · 4 comments


None yet

2 participants

class Incremental(db.Entity):
    begin = Required(datetime.datetime)

class UserStat(Incremental):
    user = Required(int)
    composite_index('classtype', user, Incremental.begin) # (1)
    composite_index(Incremental.classtype, user, Incremental.begin) # (2)

neither (1) nor (2) works :(


Even this does not work:

class Incremental(db.Entity):
    begin = Required(datetime.datetime)

class Xxx(Incremental):

class UserStat(Xxx):
    composite_index(Xxx.classtype, user, Incremental.begin)

ERDiagramError: Invalid use of attribute Incremental.classtype in entity UserStat

@kozlovsky kozlovsky added this to the 6.1 milestone Nov 5, 2014
@kozlovsky kozlovsky self-assigned this Nov 5, 2014

Oops, you are right

@kozlovsky kozlovsky closed this in b856059 Nov 6, 2014

Fixed, now this should work:

class Person(db.Entity):
    name = Required(str)
    age = Required(int)

class Student(Person):
    gpa = Required(float)
    scholarship = Required(Decimal, default=0)
    composite_index('classtype', name, gpa, 'scholarship')

Now when you define composite index, you can specify an attribute name instead of the attribute itself. For usual attribute this is not necessary, but for implicit classtype attribute this may be useful, because this attribute is not created yet when the composite index is defined.

Also, you can specify discriminator attribute explicitly. Note that in this case it is not required to call this attribute "classtype". Explicitly specified discriminator attribute can be used to define composite index right in the base class:

class Person(db.Entity):
    classtype = Discriminator(str)
    name = Required(str)
    age = Required(int)
    composite_index(classtype, name, age)

class Student(Person):
    gpa = Required(float)

Very good!

  1. Update also documentation please, that one may use strings names instead of columns when creating indexes (and also uniq_keys?)
  2. Document also usage of parent class columns in index. Yes, it's obvious, and maybe you should write about that in description of table inheritance in Pony.
@kozlovsky kozlovsky added a commit that referenced this issue Feb 20, 2015
@kozlovsky kozlovsky Pony ORM Release 0.6.1
* Closed #65: Now the select(), filter(), order_by(), page(), limit(), random() methods can be applied to collection attributes
* Closed #105: Now you can pass globals and locals to the select() function
* Improved inheritance support in queries: select(x for x in BaseClass if x.subclass_attr == y)
* Now it is possible to do db.insert(SomeEntity, column1=x, column2=y) instead of db.insert(SomeEntity._table_, column1=x, column2=y)
* Discriminator attribute can be part of the composite index
* Now it is possible to specify the attribute name instead of the attribute itself in composite index
* Query statistics: global_stats_lock is deprecated, just use global_stats property without any locking
* New load() method for entity instances which retrieves all unloaded attributes except collections
* New load() method for collections, e.g. customer.orders.load()
* Enhanced error message when descendant classes declare attributes with the same name
* Fixed #98: Composite index can include attributes of base entity
* Fixed #106: incorrect loading of object which consists of primary key only
* Fixed pony.converting.check_email()
* Prefetching bug fixed: if collection is already fully loaded it shouldn't be loaded again
* Deprecated Entity.order_by(..) method was removed. Use instead
* Various performance enhancements
* Multiple bugs were fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment