If the current_user AR class has a one-to-many or many-to-many
association named "leagues" defined then you certainly can use find on
this association in rails, ActiveRecord::Associations::ClassMethods
.
I suspect that account.listings is an active record association, as in
class Account < ActiveRecord::Base
has_many :listings
end
but current_user.leagues is some kind of Ruby collection, like an array.
A has_many association masquerades as a Ruby array for most uses, but it changes the find method (which Array gets from the Enumerable module) to to a sequel query instead of yielding to a block.
I suspect that account.listings is an active record association, as in
class Account < ActiveRecord::Base
has_many :listings
end
but current_user.leagues is some kind of Ruby collection, like an array.
A has_many association masquerades as a Ruby array for most uses, but it
changes the find method (which Array gets from the Enumerable module) to
to
a sequel query instead of yielding to a block.
I suspect that account.listings is an active record association, as in
class Account < ActiveRecord::Base
has_many :listings
end
but current_user.leagues is some kind of Ruby collection, like an array.
A has_many association masquerades as a Ruby array for most uses, but it
changes the find method (which Array gets from the Enumerable module) to
to
a sequel query instead of yielding to a block.
This is what I have:
class User < ActiveRecord::Base
has_many :league_admins
has_many :leagues, :through => :league_admins
end
class League < ActiveRecord::Base
has_many :league_admins
has_many :users, :through => :league_admins
end
class LeagueAdmin < ActiveRecord::Base
belongs_to :league
belongs_to :user
end
I guess someone spiked my coffee :). I have probably just never tried
to perform a find in the way I am now. Usually when I have a relation
like this the most I would do is view the related items, but I guess
the has_many :through only party behaves like a normal has_many.
Is there a rails way to make an association between these two classes,
since that is something else that no longer exists, or does a person
just do it manually?
ex
@league = League.new(params[:league])
League.transaction do
@league.save!
@league_admin = LeagueAdmin.new(:league_id => @league.id, :user_id
=> current_user.id)
end