Okay, I hope this doesn't get to be too long, but... I'm trying to figure out a "best practice" scenario for this and any help in its implementation would be helpful. When I started the project I am working on, I saw ActiveRecord's polymorphic relationships and thought, "Perfect!" Then, I saw the way the tables were handled and said, "Uhhh... no." I knew how I wanted the tables designed and I wanted the ORM to work with me. Thus far, DataMapper has been excellent. I know what I want to do is possible, but I'm not sure how to get it done.
Here are the models to consider: Asset AssetCategory1 AssetCategory2 Category Now, they are currently arranged as such: AssetCategoryX's primary key is asset_id, which, obviously, is an Asset instance. Asset has a field category_id which relates to a Category. And Asset could be an image, a document or whatever. They have a few things in common, like a title and an id, but an image and a document or a person or whatever asset I choose to create differ A LOT. What I want to happen is when I get an asset (through get, first or all) I want it to check its category and add an association called "extended" that creates a relationship with the proper extended model. So, what I want, is for Asset to have (I think) IF it's category 1: belongs_to :asset_category1, :name => :extended IF it's category2: belongs_to :asset_category2, :name => :extended I'm guessing I need to use one of the "before" hooks, but I'm a little confused as to which. So, I guess the real question is, can I create a relationship "on the fly" and if so, how? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
