[Seaside] How generate ID
rootbeer at redcat.com
Sat Dec 29 20:53:45 UTC 2007
On Dec 29, 2007 12:11 PM, an organic <seasidebeginner at gmail.com> wrote:
> i am writing small example in squeak seaside. I want save my objects in
> image. And i have this class Category with ID, Name. Store in
> OrderedCollection. My problem how generate next ID? i think about locking
> and find max increase one and use it but isn't there simplier way?
I'm not completely sure what you're looking for. It sounds as if you
want a class-side variable, something like this:
Object subclass: #MyClass
LastID := ifNil: [ LastID := 0 ] .
^(LastID := 1 + LastID).
Because it's a class variable, it will exist just once in the system,
instead of once for each instance of MyClass. That means that #newID
will always return a different value than the previous time, no matter
which instance receives it. Is that what you're looking for?
More information about the seaside