Is it possible to set up a double relationship in activerecord models via the generate scaffold command?
For example, if I had a User model and a PrivateMessage model, the private_messages table would need to keep track of both the sender and recipient.
Obviously, for a single relationship I would just do this:
ruby script/generate scaffold pm title:string content:string user:references
Is there a similar way to set up two relations?
Also, is there anyway to set up aliases for the relations?
So rather than saying:
@message.user
You can use something like:
@message.sender or @message.recipient
Any advice would be greatly appreciated.
Thanks.
Add this to your Model
And you are able to call
@message.senderand@message.recipientand both reference to the User model.Instead of
user:referencesin your generate command, you’d needsender:referencesandrecipient:references