I'm trying to setup sharing items. How would I do this in rails using postgresql?
Right now users has_many items. I want users to be able to share items with other users but still own those items. So users has_many items and items has_many users. I can't do has_and_belongs_to_many because I want the owner of the item to have different permissions than the shared users. How would I setup the relationship? Should items have a shared_id which somehow points to users?
EDIT: Here's what worked
#user.rb
has_many :items
has_many :sharrings
has_many :shared_items, :foreign_key => "item_id", :through => :sharrings, :source => :item
#user.rb
belongs_to :user
has_many :sharrings
has_many :shared_users, :foreign_key => "user_id", :through => :sharrings, :source => :user
#sharring.rb
belongs_to :shareduser
belongs_to :item
# create sharring
@item.sharrings.build :user_id => other_user.id
# get items shared with this user
@shared_items = current_user.shared_items