[okfn-help] vdm: contuity relation in self-referential tables

Rufus Pollock rufus.pollock at okfn.org
Wed Sep 8 19:04:50 UTC 2010


Martijn,

You've definitely found another issue. So this doesn't get lost could
you create a new ticket (under vdm component):

<http://knowledgeforge.net/ckan/trac/newticket>

I also think that the continuity stuff could do with refactoring
(there is no need to have separate continuity_id column given that we
copy across the primary key from the continuity object onto the
revision -- and the continuity_id won't work if we want to support
multi-column primary keys:
<http://knowledgeforge.net/ckan/trac/ticket/245>)

rufus

On 26 August 2010 17:48, Martijn Faassen <faassen at startifact.com> wrote:
> Hi there,
>
> With vdm for each table -> class mapping you also create a
> revision_table -> revision_class mapping.
>
> create_object_version() is what constructs both the revision class as
> well as the mapping to it. This sets up a 'continuity' relation.
>
> Things broke down however when I created a self-referential table.
> SQLAlchemy (for some reason) requires an additional primaryjoin clause
> on any relation connected to the self-referential table.
>
> But since create_object_version creates such a relation automatically
> (continuity), SQLAlchemy couldn't figure out anymore how that was
> supposed to work.
>
> This is what sets up the continuity:
>
>        'continuity':relation(base_object,
>            backref=backref('all_revisions_unordered',
>                cascade='all, delete, delete-orphan'),
>                order_by=rev_table.c.revision_id.desc()
>
> I hacked it up to add the following:
>
>    # XXX this can break if there are more than one tables
>    from sqlalchemy.orm import class_mapper
>    continuity_table = class_mapper(base_object).tables[0]
>
> and then later...
>
>        'continuity':relation(base_object,
>                              primaryjoin=(rev_table.c.continuity_id ==
>                                           continuity_table.c.id),
>            backref=backref('all_revisions_unordered',
>                cascade='all, delete, delete-orphan'),
>                order_by=rev_table.c.revision_id.desc()
>            ),
>
> i.e. I added what I hope is the correct primaryjoin expression. When I
> run the vdm tests that doesn't seem to create breakage, and it seems
> to fix the self-referential story. Though I must say the test coverage
> for 'continuity' isn't very broad..
>
> Thoughts?
>
> Regards,
>
> Martijn
>
> _______________________________________________
> okfn-help mailing list
> okfn-help at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/okfn-help
>



-- 
Open Knowledge Foundation
Promoting Open Knowledge in a Digital Age
http://www.okfn.org/ - http://blog.okfn.org/




More information about the okfn-help mailing list