Rufus Pollock wrote:
>> One thing we both noted is that in order to version relationships,
>> those relationships need to be either:
>>
>> 1. Stored as part of the main entity's table. Or,
>> 2. Be a mapped object as well.
>
> You are really want to go with 2 if both ends of the link are
> versioned. For example, for http://www.ckan.net/ I want to have a
> versioned Package and a versioned Tag object with a m2m link between
> Packages and Tags.
Agreed.
> The polymorphic association object seems to me to be a bit of
> overkill. With the standard m2m setup that elixir already has it
> is pretty easy to add associations and this polymorphic setup only
> becomes useful if there is some object that is joined to every other
> object (e.g. as with tags in some cases). Even then I think would be
> fairly easy just to wrap the existing standard m2m relationships up
> into something cleaner.
Again, I am with you.
> I agree that elixir should definitely support explicit intermediate
> objects but I'm not sure that it might not be better to leave people
> to specify them themselves rather than add it all in to one side of
> the has_and_belongs_to_many. That is I'd prefer something like:
>
> class Person(Entity):
> has_field('name', Unicode)
> # creates normal addresses property but addresses_association
> has_and_belongs_to_many(
> 'addresses',
> intermediary='PersonAddress',
> )
>
> class PersonAddress(Entity):
> has_field('type, Unicode)
> has_field('name', Unicode)
> belongs_to('person', of_kind='Person')
> belongs_to('address', of_kind='Address')
>
> class Address(Entity):
> has_field('fulladdress', Unicode)
> has_and_belongs_to_many(
> 'persons',
> intermediary='PersonAddress',
> )
Yes, I agree with you, the more that I look at the code I wrote before,
the less I like it. I have studied ActiveRecord a bit more, and what
you are showing above is actually very similar to what they have elected
to do, and I like their style a bit better. Its more like this:
class Person(Entity):
has_field('name', Unicode)
has_many('address_associations', of_kind='PersonAddress')
has_many(
'addresses',
of_kind='Address',
through='address_associations'
)
class PersonAddress(Entity):
has_field('type', Unicode)
has_field('name', Unicode)
belongs_to('person', of_kind='Person')
belongs_to('address', of_kind='Address')
class Address(Entity):
has_field('fulladdress', Unicode)
has_many('address_associations', of_kind='PersonAddress')
has_many('people',
of_kind='Person',
through='address_associations'
)
The `has_many` with a `through` keyword would simply create a property
on the entity proxying through the association objects, for convenience.
This should be really easy to implement, although I need to gain a
better understanding of the new autodelay technique to be really
confident about that.
>> Once the relationships themselves are mapped objects, it becomes
>> easier to version them using the existing `acts_as_versioned` Mapper
>> Extension.
>
> To some extent but I think this is a fairly small part of doing full
> versioning so I don' think this should be the main reason driving the
> change.
Well, its not the *only* consideration. Its also a much richer form of
relationship, and I think its easier to understand. I have never really
been a fan of the readability and clarify of `has_and_belongs_to_many`
and numerous people have complained to me that it didn't make immediate
sense to them. I think going with explicit association objects will
make things a bit easier to understand, with the added benefit that it
should make versioning a bit easier to do as well.
--
Jonathan LaCour
http://cleverdevil.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---