--- On Wed, 6/30/10, Diez B. Roggisch <[email protected]> wrote:
> > I suspect drop_all() dosen't work as I expect. I
> expect drop_all to really
> > delete the tables from the database, which is not done
> if you look at the
> > trace, and this is confirmed by the test i made : I
> manually dropped the
> > tables from the db and re-run the *same* script (not
> changing a line) and
> > it "succesfully failed" © this time.
> > 
> > What's your opinion.
> 
> I've never used drop-all, and instead dropped/re-created
> the DB.
> 
> Diez
> 


The culprit is as always the user :) setup_all needs to be called before 
issuing a drop_all, otherwise drop_all can't find any entity to drop the 
associated table.

So here's the working code and thank you for your precious help :

<code>
from elixir import *

class BaseModel(Entity):
    using_options(abstract=True)

    repr_attr = "name"

    def __repr__(self):
        """
        """
        return "<%s '%s' id='%s'>" % 
(self.__class__.__name__,getattr(self,self.repr_attr,id(self)),self.id)
   
class Country(BaseModel):
    """
    """
    using_options(tablename = "countries")

    name       = Field(Unicode,nullable=False)
    cities     = OneToMany("City")

class City(BaseModel):
    """
    """
    using_options(tablename = "cities")

    name    = Field(Unicode)
    country = ManyToOne("Country",ondelete="RESTRICT",required=True)

metadata.bind = "postgres://coriolis:coriolis234acc...@localhost/testdb"
metadata.bind.echo = True
# I use this to issue some raw sql (truncate not supported by sqla/elixir ?)
session.bind = metadata.bind
setup_all()
drop_all()
create_all()

session.commit()

# just to make them global
algeria = None
algiers = None

def create():
    global algeria,algiers
    algeria = Country(name=u"Algeria")
    algiers = City(name=u"Algiers",country=algeria)
    session.commit()

def delete():
    global algeria,algiers
    # This finally breaks ! yeaaaaaay !
    algeria.delete()
    session.commit()

create()
delete()
session.commit()

</code>

Thanks again !

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.

Reply via email to