(This is not the code I use, although it sums up the idea of ββwhat I want to do)
class Connection < ActiveRecord::Base
belongs_to :connection1, :polymorphic => true
belongs_to :connection2, :polymorphic => true
end
class User < ActiveRecord::Base
has_many :followers, :class_name => 'Connection', :as => :connection1
has_many :followings, :class_name => 'Connection', :as => :connection2
end
My question is that I want to know how I can create a "network" method, so the return is not an array. In this way,
u = User.first
u.network
So I can still do this:
u.network.find_by_last_name("James")
ETA:
Or hmm, I think my question really comes down to the fact that you can create a method that combines the 2 has_many associations in such a way that I can still call its find_by methods.
source
share