Displaying 20 results from an estimated 21 matches for "reset_column_inform".
2005 Dec 15
1
migration: counter cache & "reset_column_information"
To speed up
<%= @project.members_count %>
, I added a counter cache to the ''projects'' table with the migration
below:
def self.up
add_column "projects", "members_count", :string, :default => "0"
Project.reset_column_information
Project.find(:all).each do |p|
p.update_attribute :members_count , p.members.count
end
end
Question:
Is "Project.reset_column_information" required in the migration?
Alain
(Note: For info, I modified the ''Member'' model accordingly:
clas...
2006 Jan 19
4
multiple database in the same actions?
Hi,
I read the example in
http://wiki.rubyonrails.com/rails/pages/HowtoUseMultipleDatabases,
it show us how to connect to other database, each time
we start a new action, however, this doesn''t work
while you try to connect to two different database
within the same action.
SO I wonder is it possible to bind to two or more
database within the same action????
Thanks you very much
Saiho
2008 Feb 13
4
Migration Issues: Can't update newly added column values
...end
#
# Add `deleted_at` column, set to Time.now if `is_deleted` is true,
# then remove `is_deleted`:
#
def self.up
add_column(:options, :deleted_at, :timestamp, :default => nil)
say "IN TABLE option: Setting `deleted_at` to now if `is_deleted`
set." do
Option.reset_column_information
Option.find(:all).each do |option|
option.update_attribute(:deleted_at, Time.now) if
option[:is_deleted]
end
end
remove_column(:options, :is_deleted)
end
#
# Add `is_deleted` column, set to true if `deleted_at` isn''t NULL,
# then remove `deleted_at...
2006 Jul 14
3
Migration not updating fields
...quot;0", "owner_id"=>"0", "created"=>"2006-07-13 12:40:33", "updated"=>nil}>]
Notice it found one and of couse now if I do p.backlog_items.size it
returns 1
So I added this bit of code to the migration
# Reset the column
Product.reset_column_information
say_with_time "Updating products..." do
Product.find(:all).each do |p|
blg = p.backlog_items
p.backlog_items_count = blg.size
end
end
But it still sets the count to 0 where it should be 1, any help
appreciated...
--
Posted via http://www.ruby-forum.com/.
2006 Apr 15
8
Migrations - adding a new table and automatically creating records
...lled roles and then populate it with some new
records...This doesn''t work. Is there something I''m missing?
Craig
class AddRightsAndRolesTables < ActiveRecord::Migration
def self.up
create_table :roles do |t|
t.column "name", :string
end
Role.reset_column_information
Role.new :name => "Users Admin"
Role.new :name => "Users Create"
Role.new :name => "Users View"
Role.new :name => "Users None"
end
def self.down
drop_table :roles
end
end
2008 Oct 26
3
Undefined method f_title
Hi,
This is my migration:
class CreateSampleForms < ActiveRecord::Migration
def self.add_data
SampleForm.create(:name => ''Default (Empty)'', :f_type => ''Default
(Empty)'', :description => ''Use this template to create a blank form.'')
end
def self.up
create_table :sample_forms do |t|
t.string :name, :null =>
2006 Jan 26
0
If you want to disconnect a database properly, there is the code:)!!!
...apter =>
"postgresql",
:host => "1.2.3.4",
:port => 5432,
:database => "db1",
:username => "dbuser1",
:password => "dbuser1")
GenTableAs.set_table_name ''table_no_1''
GenTableAs.reset_column_information()
obj1 = GenTableAs.new
@col1 = obj1.class.column_names()
obj1["colaa"] = 123
obj1["colab"] = "123"
obj1.save
obj1 = nil
GenTableAs.clear_connection # here we disconnect the
connection
# connection to a new database
GenTableAs.establish_conne...
2006 Oct 15
3
Migrations - add_column :default=>true, :null=>false
This seems pretty brain dead:
add_column :types, :notify_on_create, :boolean, {:default=>true,
:null=>false}
$ rake migrate
Error: ERROR: column "notify_on_create" contains null values
: ALTER TABLE types ALTER notify_on_create SET NOT NULL
Why doesn''t Rails set the new column to true, as it''s supposed to
default to? I tried :default=>1 as well (same
2006 Aug 09
1
Migrating a Field to External Model
...ith each brand. I created
the the model and created and ran the migration to create the new
table. So far so good. Then I created a separate migration to
transfer the data. The up method looks like this:
#Migrate Product Brands
add_column :products, :brand_id, :integer
Product::reset_column_information
Product::find(:all).each do |p|
brand = Brand::create(''name'' => p.attributes[''brand'']) unless
brand = Brand::find_by_name(p.attributes[''brand''])
p.brand = brand
p.save!
end
remove_column :products, :brand
The...
2007 Feb 14
2
File into database migration
Hi,
I am trying to figure out an approach to load in our initial data into our
database.
I have written some load_data migrations which populate a lot of the stuff,
how some of the database
items are images etc and I am trying to figure out how to approach added
them to the database
during a rake db:migrate
I am thinking if I store the files in a folder off the RAILS_ROOT I should
be able to
2011 Sep 13
4
Changing adapters in ActiveRecord does not change the generated sql
If I establish a new connection with a new adapter (ie. switch from mysql to
postgresl) the generated sql is still mysql specific. I tried all sorts of
reset methods on AR::Base but to no avail. There must be something being
memoized on ActiveRecord base that has to do with the adapter and it doesn''t
get cleared when you establish a connection with a new adapter.
I know this
2011 Sep 13
4
Prepared statements and postgreSQL schemas
Hi guys.
I''m using a postgreSQL with multiple schemas. To change between schemas I
use the ''SET schema TO ...'' statement. That works ok in rails 3.0.
Rails 3.1 uses prepared statements and does not take into account the
''schema_search_path''. This is a big problem because the statement is
prepared once and then the same prepared statement is executed
2006 Jan 14
11
accessing models from migrations
Ok, so now Users need to be associated with Organizations. I''ve
created a migration and added a ''organization_id'' column to the users
table. I want the default organization_id to be the first
Organization. So I have :default => Organization.find(:first). But
it''s complaining about not being able to find the constant
''Organization''.
Any
2006 May 08
0
ActiveRecord and refreshing column info
...ase.column_names
The problem I have is that once I set the table_name to ''table_a'',
ActiveRecord always returns table_a''s column info. I''ve tried the
following ActiveRecord methods to clear the info in column_names &
neither has worked
ActiveRecord::Base.reset_column_information
ActiveRecord::Base.remove_connection
Even after removing & then restablishing the connection, the
column_names method continues to return table_a''s columns.
So I''m obviously on the wrong track here. But I can''t find out where I
should be headed. Any ideas?
T...
2006 Jan 11
0
Connection problem with a generic-runtime-built ActiveRecord::Base
...; pwd)
end
def self.closeConnection()
return ActiveRecord::Base.remove_connection()
end
def self.buildNewTableClass(className, tableName)
genClass = Class.new(GenActRec)
const_set("#{className.to_s}", genClass)
genClass.set_table_name tableName
genClass.reset_column_information()
return genClass
end
# read table Column names
def readTableColumnNames
return self.class.column_names()
end
end
this how I use it:
class GentestController < ApplicationController
def index
GenActRec.connectToPSQLDB("1.2.3.4", 5432, "gendb",
&...
2009 Feb 25
1
Problem with set_table_name
Dear friends,
I ran the following in my console.Assume I already have the
postgresql connection .
>> class D < ActiveRecord::Base
>> end
=> nil
>> D.set_table_name "users"
=> nil
>> D.column_names
=> ["id", "name", "fname", "lname", "password", "addr1", "addr2",
2006 Jul 05
2
Serialized object behaves weird
Hi!
I got a class named EinsatzFilter which I serialized to session. Before
saving to session it works afterwards I keep getting the message:
"undefined method `to_s'' for #<Person:0x38c6ab8>". "Person" is a from
ActiveRecord::Base inherited class.
Code:
class EinsatzFilter
include ApplicationHelper
attr_reader :personen, :monat, :projekte, :kunde
2009 Mar 05
7
issue with the object cache
Hi,
I am getting a method_missing error when I run my application in the
production environment unless I set config.cache_classes = false in
config/environments/production.rb. This happens in Rails 2.2.2 but not
in Rails 2.1.0. The method that is missing is one I used to have
before I edited by hand the migration that creates the table
associated with the object (I know you are discouraged to do
2006 Aug 17
3
Migrations for migrating data across databases - is it possible?
Hi All
I am trying to understand if I can use migrations to migrate data under the
following conditions
1. Across 2 different databases (Oracle/DB2) with same schemas.
2. Across 2 different databases (Oracle/DB2) with different schemas.
I am trying to avoid writing DBI/OCI8 scripts.
Can somone please shed some light if this is even possible?
thanks
-daya
-------------- next part
2010 Mar 04
25
how to share variables in data migrations (up/down)
hi there,
How do we share variables in a given data migration?
For example,
the code below fails to work because "statuses" don''t seem to be in
scope for both up and down.
class AddDefaultValuesToStatuses < ActiveRecord::Migration
statuses = [
{
''details'' => ''details'',
},
{