Hi. I’m experiencing a little problem with ActiveRecord and relations.
The idea is that I have a lfsearch model:
class Lfsearch < ActiveRecord::Base
has_many :lfresults
end
and a lfresult model:
class Lfresult < ActiveRecord::Base
belongs_to :lfsearch
end
One search has many results.
The tables are:
CREATE TABLE wozzhotdb.lfresults (
ID int(11) NOT NULL auto_increment,
lfserach_id int(11) default NULL,
name varchar(1024) default NULL,
url varchar(1024) default NULL,
imageurl varchar(1024) default NULL,
PRIMARY KEY (ID)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8
and
CREATE TABLE wozzhotdb.lfsearches (
id int(11) NOT NULL auto_increment,
query varchar(1048) default NULL,
timestamp timestamp NOT NULL default CURRENT_TIMESTAMP on update
CURRENT_TIMESTAMP,
PRIMARY KEY (id)
) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=latin1
I try to run this code:
@lastfmdb = Lfsearch.new (:query => “Hello”)
@lastfmresult = Lfresult.new (:name => “senc”, :url
=>“www.yo.com”, :imageurl => “Hola”)
@lastfmresult.save
@lastfmdb.save
@lastfmdb.add_lfresult (@lastfmresult)
But I get this error:
NoMethodError in GestorController#parse
undefined method `add_lfresult’ for #<Lfsearch id: 6, query: “Indie”,
timestamp: nil>
Thanks for your help, Any ideas? ![]()