ruby - rails has_many :through has_many :through -


i'm wondering extent can use associations in rails. take consideration following:

class user < activerecord::base     has_one :provider     has_many :businesses, :through => :provider end  class provider < activerecord::base     has_many :businesses     has_many :bids, :through => :businesses     belongs_to :user end  class business < activerecord::base     has_many :bids     belongs_to :provider end  class bid < activerecord::base     belongs_to :business end 

i able set these nifty shortcuts user.businesses , provider.bids doing user.bids? possible associate association, speak?

this entirely possible, needs little work. following model definitions used in conjunction nested_has_many plugin can fetch bids belonging user @user.bids

class user < activerecord::base     has_one :provider     has_many :businesses, :through => :provider     has_many :bids, :through => :businesses end  class provider < activerecord::base     has_many :businesses     has_many :bids, :through => :businesses     belongs_to :user end  class business < activerecord::base     has_many :bids     belongs_to :provider end  class bid < activerecord::base     belongs_to :business end 

however getting user bid take more work.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -