I am using a habtm relationship between two tables and the migration
fails when updating the join table. However, it works when doing it
step by step in the console!

Here is the code:
class User < ActiveRecord::Base
  acts_as_authentic
  belongs_to :role
  has_and_belongs_to_many :dim_teams, :association_foreign_key
=> :team_id
end

class DimTeam < ActiveRecord::Base

  set_primary_key "team_id"

  has_and_belongs_to_many :users, :foreign_key => "team_id"

end


class AddUserData < ActiveRecord::Migration
  def self.up

    role = Role.find_by_role('User')
    team1 = DimTeam.find_by_team_name('Essex')
    user = User.new
    user.login = "snapes"
    user.email = "[email protected]"
    user.password = "password"
    user.password_confirmation = "password"
    user.role = role
    user.save
    user = User.find_by_login("snapes")
    user.dim_teams << team1

  end

  def self.down
  end
end

When I run the code step by step in the console, it works. The final
user.dim_teams << team1 line produces the following output in
development.log:
SQL (2.8ms)   INSERT INTO [dim_teams_users] ([team_id], [user_id])
VALUES (13, 2)

When I run it as a rake task, I get
SQL (0.0ms)[0m  [0mDBI::DatabaseError: (102) [unixODBC][FreeTDS][SQL
Server]Incorrect syntax near ')'.: INSERT INTO [dim_teams_users] ()
VALUES ()[0m

Can anybody explain why the difference to me please?
thanks



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to