[Modeling-cvs] ProjectModeling/Modeling/doc/UserGuide FAQ.tex,1.1,1.2
Status: Abandoned
Brought to you by:
sbigaret
|
From: <sbi...@us...> - 2003-07-04 17:02:47
|
Update of /cvsroot/modeling/ProjectModeling/Modeling/doc/UserGuide
In directory sc8-pr-cvs1:/tmp/cvs-serv26741/Modeling/doc/UserGuide
Modified Files:
FAQ.tex
Log Message:
Added a technique to access the PK's value without making it class property
Index: FAQ.tex
===================================================================
RCS file: /cvsroot/modeling/ProjectModeling/Modeling/doc/UserGuide/FAQ.tex,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FAQ.tex 19 May 2003 16:05:16 -0000 1.1
--- FAQ.tex 4 Jul 2003 17:02:45 -0000 1.2
***************
*** 27,30 ****
--- 27,32 ----
\item[What if I want to see the primary key/foreign key values in my objects?]
+ \begin{description}
+ \item[Making it a class property]
Really, you should not --simply because we do not support anything but {\em
automatic} generation of {\em simple} primary key (one attribute only, no
***************
*** 41,44 ****
--- 43,72 ----
for sure. You've been warned!
\end{itemize}
+
+ \item[Accessing it at run-time]
+ However, there's a cleaner alternative to this: the primary key value can
+ always be retrieved from your objects, without requiring it to be a class
+ property. You can access it with \method{globalID}; every single object
+ managed by the framework is uniquely identified by its global id. Among other
+ things, this one has a dictionary holding the PK values:
+
+ \begin{verbatim}
+ >>> object=ec.fetch('Writer', qualifier='age<50')[0]
+ >>> object.globalID().keyValues()
+ {'id': 1}
+ \end{verbatim}
+
+ So if you need to access the PK for objects of a given class, you can add a
+ method like this one:
+ \begin{verbatim}
+ def pk(self):
+ "Returns the pk's value"
+ return self.globalID() and object.globalID()['id'] or None
+ \end{verbatim}
+
+ Note: \method{CustomObject.globalID()} can return \code{None} when an object
+ has just been inserted into an \class{EditingContext} but has not been saved
+ yet.
+ \end{description}
\end{description}
|