I have this code that is using svn externals with rails EDGE working
fine for the past couple of months. A couple of days ago, this code
died. Even after deleting vendor/rails, this code doesnt work:
class Tag < ActiveRecord::Base
has_many :taggings
has_many :events, :through => :taggings
has_many :users, :through => :taggings
end
acts_as_versioned do
def self.included(base)
base.belongs_to :user
base.belongs_to :region
end
end
has_many :taggings
has_many :tags, :through => :taggings
has_many :posts
end
Tag.find(10).users
NoMethodError: undefined method users' for #<Tag:0x26f4d08 @attributes={"name"=>"rails", "id"=>"10"}> from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/base.rb:1792:inmethod_missing’
from (irb):1
Tag.find(10).events
NoMethodError: undefined method events' for #<Tag:0x26f16e4 @attributes={"name"=>"rails", "id"=>"10"}> from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/base.rb:1792:inmethod_missing’
from (irb):2
I have this code that is using svn externals with rails EDGE working
fine for the past couple of months. A couple of days ago, this code
died. Even after deleting vendor/rails, this code doesnt work:
class Tag < ActiveRecord::Base
has_many :taggings
has_many :events, :through => :taggings
has_many :users, :through => :taggings
end
acts_as_versioned do
def self.included(base)
base.belongs_to :user
base.belongs_to :region
end
end
has_many :taggings
has_many :tags, :through => :taggings
has_many :posts
end
Tag.find(10).users
NoMethodError: undefined method users' for #<Tag:0x26f4d08 @attributes={"name"=>"rails", "id"=>"10"}> from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/base.rb:1792:in method_missing’
from (irb):1
Tag.find(10).events
NoMethodError: undefined method events' for #<Tag:0x26f16e4 @attributes={"name"=>"rails", "id"=>"10"}> from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/base.rb:1792:in method_missing’
from (irb):2
reload!
Reloading…
=> [ApplicationController, Tagging, Tag]
Tag.find(10).events #works fine now
Tag.find(10).users #works fine now
WTF!??!?!?!
Why can’t Tag use the associations?
You don’t have any belongs_to associations anywhere. Do you have foreign
keys in your taggings table? It looks like you put together your models
(and I suspect your schema as well) without really understanding how
associations are supposed to work. Take a look at some of the examples
on my blog, and read up on how this stuff works. These articles in
particular should be helpful:
Hi Josh, thanks for replying. I forgot to post the taggable table, so
it seems like I have the correct relation. I had double checked your
articles before, and I checked them again, they se accurate, I am sitll
not sure what is wrong, do you have an idea? Thanks.
I have foreign keys on the Taggings table:
class Tagging < ActiveRecord::Base
belongs_to :user
belongs_to :tag
belongs_to :event
end
Josh S. wrote:
Jason Toy wrote:
I have this code that is using svn externals with rails EDGE working
fine for the past couple of months. A couple of days ago, this code
died. Even after deleting vendor/rails, this code doesnt work:
class Tag < ActiveRecord::Base
has_many :taggings
has_many :events, :through => :taggings
has_many :users, :through => :taggings
end
acts_as_versioned do
def self.included(base)
base.belongs_to :user
base.belongs_to :region
end
end
has_many :taggings
has_many :tags, :through => :taggings
has_many :posts
end
Tag.find(10).users
NoMethodError: undefined method users' for #<Tag:0x26f4d08 @attributes={"name"=>"rails", "id"=>"10"}> from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/base.rb:1792:in method_missing’
from (irb):1
Tag.find(10).events
NoMethodError: undefined method events' for #<Tag:0x26f16e4 @attributes={"name"=>"rails", "id"=>"10"}> from /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/base.rb:1792:in method_missing’
from (irb):2
reload!
Reloading…
=> [ApplicationController, Tagging, Tag]
Tag.find(10).events #works fine now
Tag.find(10).users #works fine now
WTF!??!?!?!
Why can’t Tag use the associations?
You don’t have any belongs_to associations anywhere. Do you have foreign
keys in your taggings table? It looks like you put together your models
(and I suspect your schema as well) without really understanding how
associations are supposed to work. Take a look at some of the examples
on my blog, and read up on how this stuff works. These articles in
particular should be helpful: