svilen wrote:
>> Julien Cigar wrote:
>>
>>> Another quick question, relative to multiple inheritance.
>>> Is it common to keep a back reference to the parent class within
>>> the child class ?
>>>
> u mean theclass.__bases__? or what?
>
>
>>> The idea behind this is that I want to be able to retrieve the
>>> child from the parent.
>>>
> why u need it?
>
>
I wanted to do things like :
for p in Parent.select():
if p.isChildrenInstance():
# do stuff
elif p.isAnotherChildrenInstance():
# do stuff
mainly to avoid big queries like selecting all the children, also for
the future if I have another subclass.
(as I said, this is not possible under traditional OO of course, but
could works with backreferences.)
>> also, I know that it's not possible under "pure" OO programming,
>> but I wondered if it's dirty to do it like that ?
>>
> it is possible, depends on the language and framework.
> e.g. in smalltalk u can ask which classes are my subclasses. But this
> is talking about classes, not instances.
>
> what u mean child and parent here? if this is about tables,
> u _can_ have pure child, but that is only incomplete/partial data;
> full child is all parent attributes plus all child attributes
> (parent.join(child), that is). And for each full child (complete
> object), u have one parent-only data and one child-only data... and
> they are 1:1, so u can get one from another and vice-versa.
> i think u either have wrong model or something i don't get?
>
> if u have different attributes for different Content subtypes, then
> that means subclasses and eventualy polymorphism. Or u go the
> single_typee (singletable) way, and put all stuff in Content, and
> just check for presence/absence of some attributes.
>
>
yep I have different attributes for different content subtype, for
example I have a class Event(Content), a class News(Content), ...
and three SQL tables : contents(id pk), events(content_id pk and fk),
news(content_id pk and fk)
etc etc
as Mike suggested I will add a table content_types to avoid to many
queries, so I could to:
for p in Parent.Select():
if p.content_type.name == "news":
foo = News.get(p.content_id)
# do stuff
elif p.content_type.name == "event":
bar = Event.get(p.content_id)
# do stuff
Julien
>>> For example I have something like:
>>> assign_mapper(session.context, content.Content, t_contents,
>>> properties=dict(state =
>>> relation(state.State)))
>>>
>>> assign_mapper(session.context, folder.Folder, t_folders,
>>> inherits=content.Content.mapper,
>>> properties = dict(data =
>>> relation(content.Content, secondary=t_nodes, lazy=False)))
>>>
>>> assign_mapper(session.context, page.Page, t_pages,
>>> inherits=content.Content.mapper,
>>>
>>> properties=dict(content=relation(content.Content,
>>> backref='page')))
>>>
>>> container = Folder.get(folder_id) # I get a Folder object
>>> for data in container.data:
>>> # Here I have Content objects
>>> # and I want to be able to see if the Content is a Page or a
>>> News or ... if data.page: ...
>>> elif data.news: ...
>>> ...
>>>
>>> the other idea is to add a string like "page" or "news" in the
>>> Content table (or another table) ..
>>> what do you think is the best solution ?
>>>
>>> Thanks,
>>> Julien
>>>
>>> Julien wrote:
>>>
>>>> OK it was that !
>>>>
>>>> Thanks
>>>>
>>>> On Mon, 2007-04-02 at 12:19 -0400, Michael Bayer wrote:
>>>>
>>>>> defintiely do not call flush() on "root_folder", call it for
>>>>> the session overall. thats probably the issue, since its
>>>>> failing to get the full set of child objects properly in the
>>>>> flush.
>>>>>
>>>>> On Apr 2, 2007, at 10:44 AM, Julien Cigar wrote:
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> I'm playing a bit with Multiple Table Inheritance (the
>>>>>> Non-polymorphic way) and I got a problem which I have
>>>>>> copy/paste on
>>>>>> http://rafb.net/p/HAhx8p22.html
>>>>>>
>>>>>> Here is the basic idea of what I want to do (it's a kind of
>>>>>> CMS):
>>>>>>
>>>>>> - "Content" is the base class for all contents (Pages, News,
>>>>>> Events, Folder, ...)
>>>>>> - "Folder" is a "Content" which can contain one or more
>>>>>> "Content" (Node-like structure)
>>>>>>
>>>>>> I suspect that the problem is that I don't have a sequence for
>>>>>> my primary keys in my subclasses .. ?
>>>>>>
>>>>>> Thanks,
>>>>>> Julien
>>>>>>
>>>>>>
>
> >
--
Julien Cigar
Belgian Biodiversity Platform
http://www.biodiversity.be
Université Libre de Bruxelles (ULB)
Campus de la Plaine CP 257
Bâtiment NO, Bureau 4 N4 115C (Niveau 4)
Boulevard du Triomphe, entrée ULB 2
B-1050 Bruxelles
office: [EMAIL PROTECTED]
home: [EMAIL PROTECTED]
biobel reference: http://biobel.biodiversity.be/biobel/person/show/471
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---