[Seaside] generating relationships

Richard Peirson richardpeirson at gmail.com
Thu May 14 22:36:33 UTC 2009


I suspect that as you work on the application you'll run up against issues
like Albums that have more than one Artist. You'd probably handle that by
naming the instance variable on your Album class as artists rather than
artist and have it hold a collection. Many, if not most, albums would just
have a single Artist element in that collection but you'd be able to
accommodate more when needed.

In fact, you might even want to go down to the Track level before you assign
an instance variable to hold the artist(s). The Album, which would no longer
have an artist(s) instance variable would have a tracks instance variable to
hold all of its Track instances and the Track class would have an artists
instance variable to hold the appropriate Artist instance(s) associated to
that Track.

In that case, one way to get the artists on a particular Album would be to
implement a convenience method that iterates over all of it's tracks,
collecting each Track's artists into a Set to remove the duplicates (most
tracks on a given Album would usually - but not always - have the same
artists).

As noted by others in this email chain, all of these relationships are
controlled by the instance variables without the need to resort to dedicated
key fields.



On Thu, May 14, 2009 at 4:33 PM, Sean Allen <sean at monkeysnatchbanana.com>wrote:

>
> On May 14, 2009, at 9:58 AM, sergio_101 wrote:
>
>
>>> just relate the objects in instance variables. In collections when N and
>>> one
>>> when one :)
>>>
>>
>> so, in albums, i would have something like artistID?
>>
>>
>>> In a second phase you make convenience methods so they talk each other so
>>> they
>>> answer what you need.
>>>
>>
>> is there something like the rails 'find' function build in? so i could do
>> something like..
>>
>> Album.find(albumID).artist
>>
>>
> you dont need a find.
>
> create your domain objects so that artist is an instance variable of album
>
> when you have the album, just send it an artist message or perhaps isBy or
> whatever
>
> artist := album artist
> or
> artist := album isBy
>
> in your case, you dont ever need an id.
>
> you have Artist, Album, Songs
>
> if you want to find all albums by an artist,
> you could either have a persistent collection of artists that you go
> through, find the artist you are interested in and do something like:
>
> albums := artist albums
>
> or you could just maintain a persistent collection of albums and go through
> those, asking each who it was by.
>
> the options are pretty wide open,
> if you are using gemstone and have a ton of data, they provide special
> methods to make querying faster than iterating over a collection,
> but in the beginning, iterating over a collection would be your first step.
> ( iterating is a bad choice of words but you get the idea ).
>
>
>
>
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20090514/81258927/attachment.htm


More information about the seaside mailing list