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

Discussion in 'Ruby' started by Louis J Scoras, Sep 29, 2005.

  1. ------=_Part_2238_12142549.1128001801583
    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=
    y
    (no gems), from the location ubuntu installed the package to. Or, am I doin=
    g
    something else completely wrong?

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

    ActiveRecord::Base.establish_connection(
    :adapter =3D> "mysql",
    :host =3D> "localhost",
    :username =3D> "scora002",
    :database =3D> "accounts"
    )

    class User < ActiveRecord::Base
    has_many :accounts
    end

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

    puts 10

    Thanks!

    --
    Lou

    ------=_Part_2238_12142549.1128001801583--
     
    Louis J Scoras, Sep 29, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Punya Narra
    Replies:
    5
    Views:
    1,713
    Itai Raz
    Feb 17, 2004
  2. greg
    Replies:
    1
    Views:
    276
    Peter Strøiman
    Oct 28, 2003
  3. Tom Hartnett

    how to create stand-alone page in VS

    Tom Hartnett, Nov 7, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    1,036
    Keith
    Nov 7, 2003
  4. Xeno Campanoli
    Replies:
    1
    Views:
    140
    Xeno Campanoli
    Jul 18, 2008
  5. Plotinus
    Replies:
    2
    Views:
    303
    Tad McClellan
    Dec 17, 2004
Loading...

Share This Page