Hi.

I've been experimenting with MiddleKit, and am curious if it supports
many-to-many relations -- e.g., for classes foo and bar, a foo object
can reference any number of bar objects, and vice versa.

By my understanding of MiddleKit, creating object references involves
editing Classes.csv and declaring a variable of a type with the same
name as the object referenced. 1-to-many relations involve creating a
'list of' variable on the referencing object, and a backreference
variable on the reference object. This is demonstrated in the
video-library example in the Quick Start guide.

However, the guide doesn't explain how to create a many-to-many
relation. One would think it would involve changing the backreference
variable to a list of backreferences. For example, this:


Class,  Attribute,      Type
User,   ,               
,       uid,            string
,       policies,       list of Policy

Policy, ,                               
,       pid,            string
,       user,           User

[unnecessary columns snipped]

...which normally results in this SQL:

create table User (
    userId                         int not null primary key auto_increment,
        uid                            varchar(100) 
                                       /* WARNING: NO LENGTH SPECIFIED */ not null
        /* policies list of Policy - not a SQL column */
);

create table Policy (
    policyId                       int not null primary key auto_increment,
        pid                            varchar(100) 
                                       /* WARNING: NO LENGTH SPECIFIED */ not null,
        userId                         bigint unsigned /* User */
);

now becomes becomes this:

Class,  Attribute,      Type
User,   ,               
,       uid,            string
,       policies,       list of Policy

Policy, ,                               
,       pid,            string
,       user,           *list of* User <<<

[unnecessary columns snipped]

With this SQL:

create table User (
    userId                         int not null primary key auto_increment,
        uid                            varchar(100) 
                                       /* WARNING: NO LENGTH SPECIFIED */ not null
        /* policies list of Policy - not a SQL column */
);


create table Policy (
    policyId                       int not null primary key auto_increment,
        pid                            varchar(100) 
                                       /* WARNING: NO LENGTH SPECIFIED */ not null
        /* user list of User - not a SQL column */
);

Note the lack of the userId column from the example above. Now, I may
have misunderstood how the MiddleKit relation system works, but in my
tests, I couldn't get the program to relate the two classes:

>>> u1 = User()
>>> u1.setUid("fred")
>>> u2 = User()
>>> u2.setUid("frank")
>>> p1 = Policy()
>>> p1.setPid("policy1")
>>> p2 = Policy()
>>> p2.setPid("anotherpolicy")
>>> u1.addToPolicies(p1)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/mnt/redhat/home/jbarilla/grs/Middle/GeneratedPy/GenUser.py", line 68, in 
addToPolicies
    self.policies().append(value)
  File "/mnt/redhat/home/jbarilla/grs/Middle/GeneratedPy/GenUser.py", line 60, in 
policies
    self._policies = self._mk_store.fetchObjectsOfClass(Policy, clauses='where 
userId=%i' % self.sqlObjRef())
  File "./MiddleKit/Run/SQLObjectStore.py", line 267, in fetchObjectsOfClass
  File "./MiddleKit/Run/SQLObjectStore.py", line 313, in executeSQL
  File "./MiddleKit/Run/MySQLObjectStore.py", line 46, in _executeSQL
  File "/usr/lib/python2.1/site-packages/MySQLdb/cursors.py", line 61, in execute
    r = self._query(query)
  File "/usr/lib/python2.1/site-packages/MySQLdb/cursors.py", line 168, in _query
    rowcount = self._BaseCursor__do_query(q)
  File "/usr/lib/python2.1/site-packages/MySQLdb/cursors.py", line 112, in __do_query
    db.query(q)
_mysql_exceptions.OperationalError: (1054, "Unknown column 'userId' in 'where clause'")

It expects to find the backreference column, but no such column
exists.

Is it possible, then, to create a many-to-many relation with
MiddleKit?

Thanks in advance.

--Joe

Attachment: msg03196/pgp00000.pgp
Description: PGP signature

Reply via email to