~free.ekanayaka/storm/infoheritance

« back to all changes in this revision

Viewing changes to NEWS

  • Committer: Free Ekanayaka
  • Date: 2011-10-25 10:17:32 UTC
  • Revision ID: free.ekanayaka@canonical.com-20111025101732-chgjhm27mg3rw8o4
Add polymorphic support to Reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
Improvements
5
5
------------
6
6
 
 
7
- The Reference class now supports polymorphism, by linking to remote objects of
 
8
  different types and from  different tables. Its new "poly_type" constructor
 
9
  parameter is used to indicate a column on the local object whose value
 
10
  identifies the type of remote object. This feature can be used to implement
 
11
  the infoheritance pattern, for example:
 
12
 
 
13
    class Person(object):
 
14
 
 
15
        __storm_table__ = "person"
 
16
        id = Int(allow_none=False, primary=True)
 
17
        name = Unicode(allow_none=False)
 
18
        info_type = Int(allow_none=False)
 
19
        info = Reference(id, "person_id", on_remote=True, poly_type=info_type)
 
20
 
 
21
        def __init__(self, name, info_class, **kwargs):
 
22
            self.name = name
 
23
 
 
24
    class PersonInfo(object):
 
25
 
 
26
        person_id = Int(allow_none=False, primary=True)
 
27
        person = Reference(person_id, Person.id)
 
28
 
 
29
        def __init__(self, person):
 
30
            self.person = person
 
31
 
 
32
    @poly_type(1, on=Person.info)
 
33
    class SecretAgent(PersonInfo):
 
34
 
 
35
        __storm_table__ = "secret_agent"
 
36
        passcode = Unicode(allow_none=False)
 
37
 
 
38
        def __init__(self, person, passcode=None):
 
39
            super(SecretAgent, self).__init__(person)
 
40
            self.passcode = passcode
 
41
 
 
42
    @poly_type(2, on=Person.info)
 
43
    class Teacher(PersonInfo):
 
44
 
 
45
        __storm_table__ = "teacher"
 
46
        school = Unicode(allow_none=False)
 
47
 
 
48
        def __init__(self, person, school=None):
 
49
            super(Teacher, self).__init__(person)
 
50
            self.school = school
 
51
 
7
52
Bug fixes
8
53
---------
9
54