Re: [Modeling-users] self.getId()
Status: Abandoned
Brought to you by:
sbigaret
From: <so...@la...> - 2003-03-17 22:07:08
|
On Mon, Mar 17, 2003 at 07:24:04PM +0100, so...@la... wrote: > > > I get one question: > how could i get the id for an object (I ever see this > on the list, but i miss it). cause while working on > web using real objects (read between two transaction) > is impossible without using user session, so i think > working on id is a nice way to solve this for me. > I know that working on id is a bad habit but .. Answering myself. The doc says : "you shouldn't need to expose the PK values as class' attributes. But, ok, if you really want to do that, that is to say, if you declare them as class properties, " That 's what i did, but this is wrong too, let read this snapshot: =========================================================== from mortal.Objects.Article import Article from Modeling.EditingContext import EditingContext from Modeling.FetchSpecification import FetchSpecification # creating a new object ec = EditingContext() article = Article() article.setText('Oups') article.setTitle('Again') ec.insertObject(article) ec.saveChanges() # fetching the last inserted fetchSpec=FetchSpecification(entityName='Article') ec.objectsWithFetchSpecification(fetchSpec)[-1] <mortal.Objects.Article.Article instance at 0x85cfd44> ec.objectsWithFetchSpecification(fetchSpec)[-1].getId() # <---> the id is 0 cause the fetch isn't done here. 0 ec.dispose() # <--> after a dispose it's work . ec.objectsWithFetchSpecification(fetchSpec)[-1].getId() 26L ========================================================== 1) first i don't want to dispose each time i insert a new object cause this can really be time consumming 2) for an unknow reason right now, (perhaps i'll debug that) even calling dispose() on my ec don't force a re-fecht in a real application So do you have any idea on how shoud i try ? |