Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > [Rails] Active Record: Stand alone: code executes twice

Thread Tools

[Rails] Active Record: Stand alone: code executes twice

Louis J Scoras
Posts: n/a
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi all;

I'm trying to use active record to populate a database for querying account
information on a bunch of Unix machines.

Whenever the ":belongs_to users" association is declared in the following
code, it seems to execute the script twice--that is it prints the 10 twice.
If I remove the commented line, than it works correctly and only prints
once. Other than that, the relationships seem to be working correctly.

I'm wondering if this has something to do with how I'm accessing the librar=
(no gems), from the location ubuntu installed the package to. Or, am I doin=
something else completely wrong?

$:.unshift '/usr/share/rails/activerecord/lib'
require 'active_record'

:adapter =3D> "mysql",
:host =3D> "localhost",
:username =3D> "scora002",
:database =3D> "accounts"

class User < ActiveRecord::Base
has_many :accounts

class Account < ActiveRecord::Base
belongs_to :host
belongs_to :user # This line seems to be
belongs_to rimary_group, # a problem.
:class_name =3D> "Group",
:foreign_key =3D> "primary_group_id"
has_and_belongs_to_many :groups

puts 10




Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Code in Page_Load executes twice David C ASP .Net 5 08-09-2007 02:17 PM
aspx page executes twice ASP .Net 0 03-27-2006 04:18 PM
page_load executes twice ? erdem ASP .Net 3 07-23-2004 08:28 PM
"onClick" using c# / ASP.NET executes twice on a single click? Phil Sweeney ASP .Net Web Controls 1 12-05-2003 06:04 PM
Stumped - page executes twice sometimes (even thrice occasionally!) Manny ASP General 9 08-30-2003 02:36 PM