Greg Tomei
2006-Aug-22 19:25 UTC
[Rails] multiple types of or naming polymorphical relationships
I am trying to solve this problem regarding polymorphically related objects. Consider this example, which i currently used in my application: user = User.find(1) t = user.token t.destroy I am going to change the relationship between users and tokens to be one-to-many because there are several cases that a user would have a token created for them. In my applicaiton, some cases are account verification, password reset, for example. I want to be able to use it like this: user = User.find(1) email_t = user.email_token pwd_t = user.password_token The catch is that i need to be able to tell which token is which, so that user.email_token returns the proper single token out of the collection of tokens which are stored in the database table. Since these tokens are related to security features, it is important that each is properly identified. This would also provide a nice API on my ActiveRecord object that i would use elsewhere once i have it, but on my User model it is more pressing. Has anyone else encountered this need? How did you address it? There are a couple work arounds i can think of, but there is probably a better way to do this than having fake/stub model classes or adding more columns to the database. Currently my User model is pretty simple, and its table does not have a "type" column. Much appreciated.. Greg -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---