On Jan 4, 2009, at 12:53 PM, Dan Kubb (dkubb) wrote:
> > Roy, > >> Just curious if you are considering relationship dissolution >> as part of your association rewrite? I didn't see any specs >> for it. >> >> IMO, it would be nice to support two types: >> 1) Just remove the relationship. >> 2) Destroy the relationship and the object on the other end >> of the relationship > > Would you mind providing more examples of what you're looking for? > > There's already the Collection#destroy and Collection#destroy! methods > which may do some of what you want. There are shared specs for those > two methods that are being used for One To Many and Many To Many > associations, which inherit some of the behavior from Collection. > Both of those (will) remove the Resource at the other end, and in the > case of many to many will also remove the join record since DM tries > to ensure there aren't any orphan records left laying around when > possible. For the first case: There are times when you just want to disassociate two objects without destroying them. Currently you have to look up the join record, delete it, then reload the associations: article = Article.first category = article.categories.first join = ArticleCategory.first(:article_id => article.id, :category_id => category.id) join.destroy unless join.nil? article.categories.reload category.articles.reload To accomplish the above, it would be nicer to be able to say something like: article.categories.first.divorce Here's a first draft of a spec: http://gist.github.com/43165 Thank you, Roy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "DataMapper" 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/datamapper?hl=en -~----------~----~----~----~------~----~------~--~---
