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

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

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