[SQLObject] Re: SQLObject mixins

Top Page
Author: Randall Smith
Date:  
To: sqlobject-discuss
Subject: [SQLObject] Re: SQLObject mixins
Jason Chu wrote:
> I read a little bit of discussion on mixin classes in the archives, but
> nothing was finalized.
>
> My use case sounds something like this:
> - I have objects I want to track last modified date and deleted attribute on
> - Code will be exactly the same between totally disparate classes
>
> Having one class Modifiable to do the modified date stuff works fine.
> Having one class Deletable also works fine.
>
> If something is Modifiable, it's a subclass of Modifiable. I'm know this
> isn't how sqlobject.inheritance is supposed to work, but I'm pretty sure
> this is how SQLObject inheritance is supposed to work (line 273 of main.py).
>
> The problem is when I want something to be Modifiable and Deletable. The
> new class only gets the columns from the first parent and ignores the
> second one. I think this is also because of line 273 from main.py, but I
> couldn't figure out how to make it take the columnDefinitions from all
> parents.
>
> Instead I wrote a small ugly patch to do something like _inheritable does.
> It uses _mixIn and will add all columns from mixed in parent classes to
> children.
>
> There are lots of limitations and side-effects:
> - I don't know how it fits with sqlobject.inheritance.
> - It doesn't mixin joins or indexes.
> - The first parent's columns are still included by SQLObject inheritance,
> which I'm sure will have weird side-effects later on.
>
> I figured I'd send the patch just to get some discussion going about mixins
> though. If they're not the best solution for this case, then feel free to
> say that as well.
>
> Jason
>
>
>
> ------------------------------------------------------------------------
>
> Index: sqlobject/main.py
> ===================================================================
> --- sqlobject/main.py (revision 1232)
> +++ sqlobject/main.py (working copy)
> @@ -738,6 +738,14 @@
> cls.sqlmeta.columnDefinitions['childName'] = col.StringCol(
> name='childName', default=None)
>
> + for superclass in cls.__bases__:
> + if hasattr(superclass, '_mixIn') and superclass._mixIn:
> + implicitMixInColumns = _collectAttributes(
> + superclass, superclass.sqlmeta.columnDefinitions, col.Col, set_name=True, sort=True, delete=False)
> + for i in implicitMixInColumns:
> + if i not in cls.sqlmeta.columnDefinitions.values():
> + implicitColumns.append(i)
> +
> ######################################################
> # Set some attributes to their defaults, if necessary.
> # First we get the connection:


I am dealing with the same issue. What did you end up doing?

Randall



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@???
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss