On 8/12/07, Jonathan LaCour <[EMAIL PROTECTED]> wrote: > > Rufus Pollock wrote: [snip] > > As I'd already been wondering whether I might be able to contribute > > the code into elixir as an extension, now that you already have > > something I'd very much like to: > > > > a) contribute/merge what I already have (if that would be useful). > > > > b) contribute to developing this feature (as part of elixiir) as it > > goes forward. > > I advised Rufus that it would be best to work off of the versioning > support that I added to SVN a few weeks ago. He agreed, and now we are > talking about how to version relationships. > > 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. > This brings me to an interesting point. I think we sould deprecate > the current style of many-to-many relationships in favor of something > more powerful, that is more similar to the associable plugin. Rails' > ActiveRecord has already done this, in favor of `has_many_through`, > which uses association objects. Mike Bayer blogged a bit about the > concept here: http://techspot.zzzeek.org/?p=13. I think we should try > and integrate these ideas directly into the core. Here was one idea I > cooked up that might work: 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. > It would be nice if the current `has_and_belongs_to_many` statement > would always generate an association object, but would hide it if > you didn't need it, or would let you add additional fields into the > relationship itself if you wanted that ability: > > class Person(Entity): > has_field('name', Unicode) > has_and_belongs_to_many( > 'addresses', > of_kind='Address', > with_attributes={ > 'address_type' : Unicode, > 'address_name' : Unicode > } > ) > > class Address(Entity): > has_field('fulladdress', Unicode) > > p = Person.query().get(1) > print p.addresses[0].address_type > print p.addresses[0].address_name > print p.addresses[0].target > > p.addresses.append( > Person.addresses_association( > address_type='Home', > address_name='My Home Address', > target=Address(fulladdress='123 Main St.') > ) > ) 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 property as well 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', ) p = Person.query().get(1) print p.addresses # list of addresses print p.addresses_association # list of PersonAddress objects print p.addresses_association[0].address_name print p.addresses_association[0].target p.addresses_assoication.append( Person.addresses_association( address_type='Home', address_name='My Home Address', target=Address(fulladdress='123 Main St.') ) ) p.address.append(Address(fulladdress='blah')) # default values for association attributes > Another alternative would be to do it more in the style of Rails, and > modify our `has_many` statement: > > http://wiki.rubyonrails.org/rails/pages/ThroughAssociations The example here seems to be more about developing a simple m2m property in the style that elxiir has already implemented. This page seems to be more about the polymorphic stuff Mike Bayer was posting about: http://wiki.rubyonrails.org/rails/pages/PolymorphicAssociations > 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. > Any thoughts? Regards, Rufus --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
