If the relationships are in place...
calls=Call.find(:all, :conditions => {:login_id => 1},:include =>
:logins)
calls.each {|call| puts call.comment + "\t" + call.created_at.to_s +
"\t" + call.login.to_s}
w/o knowing more about the schema, that's all i can really help with
I believe that the relationships are in place and that the schema is
compatible:
thufir@arrakis ~/goodfellow-tool $
thufir@arrakis ~/goodfellow-tool $ script/console
Loading development environment.
calls=Call.find(:all, :conditions => {:login_id => 1},:include
=> :logins)
ActiveRecord::ConfigurationError: Association named 'logins' was not
found; perhaps you misspelled it?
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/associations.rb:1351:in `build'
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/associations.rb:1356:in `build'
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/associations.rb:1355:in `each'
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/associations.rb:1355:in `build'
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/associations.rb:1319:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/associations.rb:1037:in `new'
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/associations.rb:1037:in `find_with_associations'
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/associations.rb:1036:in `catch'
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/associations.rb:1036:in `find_with_associations'
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/base.rb:996:in `find_every'
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/base.rb:418:in `find'
from (irb):1
quit
thufir@arrakis ~/goodfellow-tool $
thufir@arrakis ~/goodfellow-tool $ cat app/models/call.rb
class Call < ActiveRecord::Base
belongs_to :login
def report
Call.find(:all, :include => [:logins, :login])
end
end
thufir@arrakis ~/goodfellow-tool $
thufir@arrakis ~/goodfellow-tool $ cat app/models/login.rb
class Login < ActiveRecord::Base
belongs_to :employee
has_many :call
end
thufir@arrakis ~/goodfellow-tool $
thufir@arrakis ~/goodfellow-tool $ cat db/migrate/001_calls.rb
class Calls < ActiveRecord::Migration
def self.up
create_table "calls" do |call|
call.column "login_id", :string
call.column "created_at", :datetime
call.column "comment", :string
end
Call.create :login_id => "1",
:comment => "start work"
Call.create :login_id => "1",
:comment => "start call"
Call.create :login_id => "1",
:comment => "start break"
Call.create :login_id => "2",
:comment => "start work"
end
def self.down
drop_table "calls"
end
end
thufir@arrakis ~/goodfellow-tool $
thufir@arrakis ~/goodfellow-tool $ cat db/migrate/003_logins.rb
class Logins < ActiveRecord::Migration
def self.up
create_table "logins" do |login|
login.column "login", :string
login.column "employee_id", :string
end
Login.create :login => "0123",
:employee_id => "1"
Login.create :login => "1234",
:employee_id => "1"
Login.create :login => "2345",
:employee_id => "2"
end
def self.down
drop_table "logins"
end
end
thufir@arrakis ~/goodfellow-tool $
thanks,
Thufir