[Seaside] Equivalent of unique keys in a persistent object model ?

Miguel Enrique Cobá Martinez miguel.coba at gmail.com
Sun Jan 17 18:03:03 UTC 2010

El dom, 17-01-2010 a las 15:51 +0000, recursive68 at gmail.com escribió:
> Hi,
> I'm a newby to ST and Seaside. I attempting to port web app that's
> written in Oracle/Java over to Seaside running on Pharo. The current
> application uses Oracle sequence generated unique id's for unique
> identifiers for records, is there a parallel to this when using just
> objects persisted in the Pharo image ? I know I can code my one
> implementation to replicate this but wondered whether this is the best
> way to model it, what are the alternatives and if it is the best way,
> is there a ready made package that I could use to generate unique
> id's ?


respect to your questions, in having a unique identifier is or medium
difficult or completely unnecessary. Look, if you use the identifier to
relate two rows in different tables (as a primary key in the first and a
foreing key in the second) but only for that, then you don't need to
code that in smalltalk, you only make one object reference (by storing
the first object in a instance variable of the second object) between

ClassA has instance variables "a" and accessors "a" and "a:" that read
and write that instance variable. Same for ClassB.

Now, if you want to make objects of ClassB "know" an object of ClassA

objectA = ClassA new.
objectB = ClassB new.
objectB b: objectA. "This in fact is making a reference from B to A"

In this example, if you have an object of class B, and has stored an
object A before, you can always reference that object A anytime. No need
to have a number to reference it. 

If you need to know an index (maybe because is the invoice number and
your reports must shown that number) then you can get this, by following
the previous example, by storing everything in a OrderedCollection and
then, when you need the number, you use the position of the item in the
collection as your unique identifier. For this you can either convert
the collection to an array (costly if you have several thousands of
elements because you're essentially duplicating every item) and use the
index of each element of the array or send the collection the
keysAndValuesDo: message to get the item and their index in the
collection, e.g.

youCollection keysAndValuesDo: [ :index :value |
 "write your report"
  Transcript show: index; show: ' '; show: value; cr ].


> Jon 
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

Miguel Cobá

More information about the seaside mailing list