Hi, I am not working with megrok.rdb these days neither with grok... but, did you see rdb.Container and rdb.QueryContainer? I am not sure, but maybe it could help you with this.<div><br></div><div>Regards,<br><br><div class="gmail_quote">

On Mon, Oct 25, 2010 at 7:02 PM, Hector Blanco <span dir="ltr">&lt;<a href="mailto:white.lists@gmail.com">white.lists@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Hi list!<br>
<br>
I am trying to migrate my application from ZopeDB to MySql. I am using<br>
megrok.rdb.<br>
<br>
I have a class which inherits from list() and has a few extra methods.<br>
<br>
That class acts as a container of other classes and is used (as an<br>
attribute) in other classes as well:<br>
<br>
class MyEntry(object):<br>
        def __init__(self):<br>
                self.field1 = “field1”<br>
                self.field2 = “field2”<br>
<br>
class MyContainer(list):<br>
        def __init__(self):<br>
                super(MyContainer,self).__init__()<br>
<br>
        def append(myEntry):<br>
                if isinstance(myEntry, MyEntry):<br>
                        super(MyContainer, self).append(myEntry)<br>
<br>
        def getByField1(self, field1):<br>
                for element in self:<br>
                        if element.field1 == field1:<br>
                                return element<br>
                return None<br>
<br>
        [ ... more useful methods ...]<br>
<br>
class MyClass(object):<br>
        def __init__(self):<br>
                self.container1 = MyContainer()<br>
                self.container2 = MyContainer()<br>
                self.anotherField = “hello world”<br>
        def getContainer1():<br>
                return self.container1<br>
        def getContainer2():<br>
                return self.container2<br>
<br>
I don&#39;t really know how to model this with megrok.rdb. I kind of see<br>
clearly (although I may be totally wrong) that MyEntry and MyClass<br>
should extend from rdb.Model and each of them should be stored in a<br>
table, but I don&#39;t really know what to do with “MyContainer”. I&#39;d like<br>
to keep it inheriting from list, but I don&#39;t know how to model that.<br>
It really only needs to be an association between [id, id_of_my_entry]<br>
(relationship 1:N). In MyClass, each of the containers would get an id<br>
and then, if I want to get the “MyEntries” that are in container1, I<br>
just need to get the MyEntries who are linked to that id.<br>
<br>
… but I have no idea about how to implement that... Any hint I could<br>
get would be deeply appreciated.<br>
<br>
Thank you in advance!<br>
_______________________________________________<br>
Grok-dev mailing list<br>
<a href="mailto:Grok-dev@zope.org">Grok-dev@zope.org</a><br>
<a href="https://mail.zope.org/mailman/listinfo/grok-dev" target="_blank">https://mail.zope.org/mailman/listinfo/grok-dev</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Santiago Videla<br><a href="http://www.linkedin.com/in/svidela">http://www.linkedin.com/in/svidela</a><br><br>Sigue la mata dando de que hablar siempre abajo y a la izquierda donde el pensamiento que se hace corazón resplandece con la palabra sencilla y humilde que l@s tod@s somos.<br>


</div>