No ideas ? 

--- On Sun, 8/29/10, chaouche yacine <[email protected]> wrote:

> From: chaouche yacine <[email protected]>
> Subject: [elixir] Auto-delete operations in ManyToOne relationships (from the 
> One side) ?
> To: "elixir" <[email protected]>
> Date: Sunday, August 29, 2010, 8:47 AM
> Hello list,
> 
> Suppose I have the following simple models :
> 
> 
> == models.py ==
> from basemodel import BaseModel
> from elixir import *
> 
> class Person(Entity):
>     name = Field(String)
>     city = ManyToOne("City")
> 
> class Country(Entity):
>     """
>     """
>     using_options(tablename = "countries")
> 
>     name       =
> Field(String)
>     cities     =
> OneToMany("City")
> 
> class City(Entity):
>     """
>     """
>     using_options(tablename = "cities")
> 
>     name    = Field(String)
>     country =
> ManyToOne("Country",ondelete="RESTRICT")
> 
> 
> Is there a way to have the following behaviour :
> 
> from db import DB
> from models import *
> db      = DB()
> algeria = Country(name="Algeria")
> algiers = City(name="Algiers")
> 
> db.flush()
> # This will add algiers to algeria.cities
> algiers.country = algeria
> print algeria.cities
> # Should print [<City "Algiers">] with proper
> __repr__ method.
> algiers.remove()
> db.flush()
> # I wish that algeria.cities to be empty now []
> print algeria.cities
> # > [] ? is this possible ?
> 
> Some people told me about the AssociationProxy extension
> for salalchemy, but I don't know if that would fit in my
> case.
> 
> Or is this related to cascade deletes by any chance ? in
> which case, how should I define it ?
> 
> Any suggestions ?
> 
> 
> Here's db.py just in case :
> 
> == db.py ==
> from elixir import *
> class DB:
>     session = session
>     def __init__(self,echo=False):
>         metadata.bind =
> "postgres://some_url/testdb"
>         metadata.bind.echo = echo
>         metadata.echo   
>   = True
>         session.bind   
>    = metadata.bind
>         setup_all()
>         drop_all()
>         create_all()
>         session.commit()
> 
>     # def drop_all(self):
>     #     drop_all()
> 
>     # def create_all(self):
>     #     create_all()
> 
>     # def setup_all(self,create=False):
>     #     setup_all(create)
> 
>     def commit(self):
>         session.commit()
> 
>     def flush(self):
>         session.flush()
> 
> 
> Thanks.
> 
> Y.Chaouche
> 
> 
> 
> 
>       
> 
> -- 
> You received this message because you are subscribed to the
> Google Groups "SQLElixir" 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/sqlelixir?hl=en.
> 
> 


      

-- 
You received this message because you are subscribed to the Google Groups 
"SQLElixir" 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/sqlelixir?hl=en.

Reply via email to