search for: set_table_name

Displaying 20 results from an estimated 217 matches for "set_table_name".

2006 Mar 25
4
dynamic set_table_name for achives
How can I pass something to set_table_name so that I can switch tables on the fly for accessing archive data? If I could access sessions inside a model I would do something like: if @session[:current_period] set_table_name "statistics_" + @session[:archive_year] else set_table_name "statistics_" + Date.now.year en...
2006 Jul 22
3
Extend dynamically a model
Hello, I''ve a model defined as class Account < ActiveRecord::Base end This maps a mysql table Accounts. I want to be a able to dynamically change this model. During the life of my app, the table Accounts may change name, how do I do a set_table_name not within account.rb? -- Posted via http://www.ruby-forum.com/.
2007 Jan 14
2
rspec and set_table_name?
Hi there I have a Value class in my Rails app; however ''values'' is a reserved word in MySQL so in my value.rb file, I''ve declared set_table_name as ''vals''. However, in setting up my specs for this model, I''m hitting errors that seem to be resulting from rspec not seeing the set_table_name declaration in my model file. For instance, rspec is throwing a MySQL error as it is attempting to delete records fro...
2009 Mar 18
1
set_table_name woes, fragmented domain class
...ix which corresponds to the id of the model to which all records in that particular table belong. For example, if I have a Domain AR object with an id of 20, all DomainURL objects that :belong_to that particular Domain object are stored in table domain_urls_20. This necessitates a call to set_table_name before the DomainURL objects are fetched, like so: DomainURL.set_table_name "domain_urls_" + domain.id However, when I go into production mode, I get mismatched table and column names on my find''s. I am assuming this is caused by ActiveRecord caching the domain model so t...
2008 Jun 19
0
Error loading fixtures with classes that set_table_name
Hi all, I just hit a big wall involving a legacy database. I''ve got an active record class called "School" that uses "set_table_name ''old_school''" to map to a legacy database table: class School < ActiveRecord::Base set_table_name ''old_school'' end It works great, until I''m testing and I want to use fixtures. I''ve got a fixtures file called "old_school.yml&qu...
2008 Jun 23
0
Error loading fixtures for classes that set_table_name
Hi all, I just hit a big wall involving a legacy database. I''ve got an active record class called "School" that uses "set_table_name ''old_school''" to map to a legacy database table: class School < ActiveRecord::Base set_table_name ''old_school'' end It works great, until I''m testing and I want to use fixtures. I''ve got a fixtures file called "old_school.yml&qu...
2006 May 15
8
set_table_name and self.table_name
I have some legacy tables that I used set_table_name on, I''m attempting to write a method that will get key value from a sequence table and then update it and return a value. I''m hoping to put this in the base ActiveRecord method so I would like to reference the table name with self.table_name or something... class Contacts &l...
2006 Apr 07
6
Foreign Key naming convention override
I am working with an existing database and have to keep all table and field names as they are. ''tblcustomers'' and ''tblitems'' are linked by the ''tblcustomers'' id field ''tblcustomersid''. In ''tblitems'', the foreign key is called ''txtcustomerid''. I have already set the customers model to
2006 Jul 25
0
including database in set_table_name
Hi, Is there any reason why it would be a bad idea to include the database name, ie: set_table_name ''database.tablename'' in my models? We have legacy tables spread across several databases in MySQL and we use separate base classes for each which have their own establish_connection''s to ensure they connect to the correct database. The problem with this is that the :...
2006 Apr 01
1
set_table_name and fixtures
Hello, I''ve encountered a fixtures really frustrating bug : model, YAML file and db table names must be the same because of the fixture library ignoring the set_table_name provided in the model. Is there anything to do ? Thanks -- Posted via http://www.ruby-forum.com/.
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", "city", "state", "email", "created", "gender"] >> D...
2006 Apr 18
7
Connecting to multiple databases
Hi Everyone, I am trying to connect to multiple databases and followed along the Recipe in Chad Fowlers ''Rails Recipes'' book (which basically is about establishing the connection in a subclass of ActiveRecord::Base, and inheriting all classes in need of this connection from this class) Chad Fowler says: "You won''t be able to instantiate an External, of course,
2006 Jan 18
3
legacy database on remote host
...ally write to get the data. select * from child,parent where CONCAT(SUBSTRING(child.item_number,1,14,''00'') = parent.order_number and parent.order_number = ''4444444444444400'' Here are my models and my database.yml class Parent < ActiveRecord::Base set_table_name :parent set_primary_key :order_number has_many :child, :class_name => ''AppName'', :finder_sql => "select child.* from child,parent " +...
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
2006 Jan 17
15
legacy database and finder_sql nightmare!
...These two tables are liked by the item_number and the order_number, but not as you might think. If the order_number is 2500, then each entry in the name table will have it''s item number incremented by 1 (i.e. 2501,2501,2503). Here are my models class Order < ActiveRecord::Base set_table_name :order set_primary_key :order_number has_many :name, :finder_sql => ''SELECT * from name where name.item_number like CONCAT(SUBSTRING(#{order_number},1,14),\''%\'')'' end ~ class Name < ActiveRecord::Base set_table_na...
2009 Apr 24
4
Overriding Model Name
If I understand things correctly, by default, Rails expects both the ActiveRecord class name and the model name (i.e., the name of the file that contains the definition of the ActiveRecord class) to be the singluar of the table name. How can I override this default behavior with respect to the model name? That is, I would like to have the file name of the file that contains the definition of the
2006 Jul 25
2
join in legacy DB?
I''ve got a problem with some tables that don''t follow any RAILS standards. how do I define the join in the model when all three tables have wacky names? class Machine < ActiveRecord::Base set_table_name "tbl_CodeMgmt_Host" set_primary_key "Id" end class Pool < ActiveRecord::Base set_table_name "tbl_CodeMgmt_Pool" set_primary_key "Id" end the join table is tbl_CodeMgmt_PoolHost with columns CodeMgmtPoolId CodeMgmtHostId any clues? thanks -zaq --...
2006 Apr 11
1
Foreign Keys
...s are as follows: "tblusers" - primary key "TblUsersID" "tblregisteredphones" - primary key "TblRegisteredPhonesID" - foreign key "intUserID" My models are as follows: class Registeredphone < ActiveRecord::Base set_table_name "tblregisteredphones" belongs_to :user, :foreign_key => "intUserID" set_primary_key(:TblRegisteredPhonesID) end class User < ActiveRecord::Base set_table_name "tblusers" has_many :registeredphones, :foreign_key => "TblUsersID" set_p...
2006 Apr 19
1
Separate databases for reads and writes?
Hi all - New to rails... been reading as much as I can though and have yet to find a solid answer (although I think I found an unsolid negative). I''m wondering if there''s a way to split up the reads and writes in Rails so that pages/actions that don''t need to write can query from a group of mirrored databases. And my content managers can update a single master. I
2006 Mar 03
0
AR::Base.pluralize_table_names doesnt work with scaffold generator, right?
...scaffold model Something then it throws an error saying that my database scheme doesnt have a Something. However there is a table called something. If I then change my something table to somethings and rerun the command, then it works fine. Then I have to edit model/Somthing.rb and inlcude the set_table_name "Something" into the class definition, rename my table back to something and also fix the test-classes because they got generated with the somethings name. Seems to be a bit error prone to me and very unelegant. pgAdmin makes the sql part easy, but it still feels a bit strange to me....