[Ruby] Using ActiveRecord outside Rails
Ryan Davis
ryand-ruby at zenspider.com
Mon Oct 2 22:31:36 PDT 2006
On Oct 2, 2006, at 4:16 PM, Jeffrey Hulten wrote:
> So I am trying to use ActiveRecord in a series of Rake tasks for
> work and I
> am running into some issues. When I run my script I get the
> warnings below
> and then the script hangs. It is hanging on a simple find(1). Any
> help
> would be appreciated.
First off, turn off the warnings. Rails sucks in that regard hands
down. Second, please use a mailer that doesn't butcher your code
pastes. Third, cut the unrelated crap out of your email so we can
focus on the problem at hand. We haven't been working with this code
as long as you have been.
> sulla:~/Projects/ASD/INF_0609R2 jeffh$ rake test:models
> (in /Users/jeffh/Projects/ASD/INF_0609R2)
> /usr/bin/ruby -w
> [snip]
> The model:
>
> require 'ar_connection'
> class Program < ActiveRecord::Base
>
> has_many :branches
>
> belongs_to :program_manager,
> :class_name => 'Person',
> :foreign_key => 'pm_id'
> end
>
>
> The connection file:
>
> require 'rubygems'
> require 'active_record'
>
> conn = ActiveRecord::Base.establish_connection(
> :adapter => 'mysql',
> :host => 'host.company.com',
> :port => 3307,
> :database => 'tools_dev',
> :username => 'ME',
> :password => 'MINE'
> )
>
> The model test:
>
> require 'test/unit'
> require 'program'
>
> class TestModelPrograms < Test::Unit::TestCase
>
> def test_find
> program = Program.find(1)
> assert_equal('MAINT', program.short_name)
> end
> end
The rest of this looks fine, once chopped up... what does the dev log
show?
More information about the Ruby
mailing list