search for: set_primary_key

Displaying 20 results from an estimated 131 matches for "set_primary_key".

2007 Apr 17
0
set_primary_key issue
Hi: I am new to the ruby and rails. What I am tried to do is to create a scaffold based on an existing table in a MS SQL Server database. Before I used the set_primary_key method, edit and show does not work in the generated code. Rails displayed the list of the records ok, but can not determine the id for each record. Create a new record does work properly, however. After I used the set_primary_key method to set the right primary key (Uesr_ID), rails can now deter...
2008 Dec 22
3
how to use set_primary_key?
We are trying to use set_primary_key to cause an existing rails db to use a different primary key. This works find for accessing existing data, but gives an error when we try to add a new record, as it seems to still be accessing the record by the default id field at that point. Are there other changes we need to make to get a...
2006 Mar 09
2
turn off auto increment
Hello, I have an old table that handles sessions. the primary key is a field called session_id and is the actual session id like "8df838303ufdfu838" however when i do the following in the model: set_primary_key "session_id" and the following in the controller: @session_hash = { "session_id" => @session.session_id, "session_user_id" => @entry.user_id, "session_ip" => encode_ip, "session_time" => Time.now } it wont update the session_id as n...
2006 Jul 07
5
link_to: link is missing id
I''m using a legacy table, where the unique id is not ''id'' I have a Model class like the following: class Article < ActiveRecord::Base set_primary_key "ARTICLE_ID" end however, using a link_to like the following (modified scaffolding), the link has no id value: <% for article in @articles %> <tr> <% for column in Article.content_columns %> <td><%=h article.send(column.name) %></td> <% e...
2005 Jul 25
0
sqlsever, scaffold and set_primary_key
I found what was wrong with sqlserver adapter. I can rename "id" to other name and it works. Only scaffold does not work correctly. It ignores my set_primary_key command and is looking for "id" name. -- JZ
2006 Mar 15
1
Through method problems with custom foreign_keys
..., company_branch es WHERE (company_branches.branch_id = contacts.company_branch_id AND contacts.p erson_person_id = 1) Notice that "contacts.company_branch_id" does not exist, it should be "contacts.com_branch_id" Here are the models: class Person < ActiveRecord::Base set_primary_key "person_id" has_many :contacts, :foreign_key=>"person_person_id", :class_name=>"Contact" has_many :company_branches, :through=>:contacts, :foreign_key=>"com_branch_id" end class CompanyBranc...
2006 Jan 18
3
legacy database on remote host
...ect * 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 27
4
find.collect problem.
...self.find_all(["bug_id = ?", reference]).collect {|b| [ b.client_id.strip << " - " << b.client_ref.strip ]} end This works fine. However this returns the reference to the client. I want the full name using this function. class Bugclient < ActiveRecord::Base set_primary_key "bc_ref" def self.fullname( reference ) result = Bugclient.find(reference.strip) result.bc_name end end However I am not sure how to combine the two so that the client full name is collected instead of the reference. I have tried the simpleton approach of @bugclientrefs...
2006 Jan 17
15
legacy database and finder_sql nightmare!
...d 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_name :name set_primary_ke...
2006 Feb 03
3
My associations are coming out nil.
...on, which contains models for both User and Country, to be able to draw the dropdown list of available countries on the edit page, like it does in all the tutorials. My model classes look like this: class User < ActiveRecord::Base belongs_to :country, :foreign_key => "CountryId" set_primary_key "userId" end and class Country < ActiveRecord::Base has_many :user set_primary_key "countryId" end but when I inspect my user class after it has been instanciated, I get this: inspect: #<User:0x4062a68 @attributes={"userName"=>"sese daxnebwo...
2006 Feb 28
4
multiple keys table
probablly a newbie question: Rails does not support a table with multiple keys ??? it seems that the ActiveRecord set_primary_key method can only set the column name... (hope i''m wrong there) example: table A - P.K id, string name table B - P.K id, string name table C - P.K a_id and b_id, both are also foreign keys. Thanks, Amir. -- Posted via http://www.ruby-forum.com/.
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 -- Posted via http://www.ruby-forum.com/.
2006 Apr 11
1
Foreign Keys
..." - 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_primary_key(:TblUsersID) end Is this correct? Thanks, Alana -- Posted via http://www.ruby-forum.com/.
2008 Jan 23
1
Making Parents object attributes available
Hello, I have a class Person class Persoon < ActiveRecord::Base set_table_name "Persoon" set_primary_key "p_persoon" has_many :adres, :class_name => "Adres" composed_of :name, :class_name => Name, :mapping => [ [:naam,:naam], [:voornaam,:voornaam], [:voornaam2,:voornaam2], [:persnickname,:persnickname], [:perssortname,:perssortname] ] def somemethod(string) .....
2006 May 15
8
set_table_name and self.table_name
...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 < ActiveRecord::Base set_table_name "contact_person" set_primary_key "p_key" def get_next_id ActiveRecord::Base.connection.execute("update #{self.table_name}_seq SET id = id+1") res = ActiveRecord::Base.connection.select_value("SELECT * FROM #{self.table_name}_seq"); res[''id''] end d...
2006 Jul 22
3
Connection refused - connect(2)
Dear all, Please help me in this regards, I am using models to access LegacySchemas using set_table_name and set_primary_key... [code for model] class CdDetails < ActiveRecord::Base def self.find_data set_table_name ''cd_details'' set_primary_key ''cd_label'' find (:first, :select => "cd_label") end end [/code] and calling th...
2006 Jan 19
5
limits of has_and_belongs_to_many
I''m experimenting with Rails on the Recipes example first before I dive into applying it to my intended application. I''m exploring which will be more work: to rename all the primary id''s in the legacy database, or to work around the fact that the primary id''s are not called ''id'' within RoR instead. I''ve been successful in using a
2006 Feb 14
6
[newb] Find vs Find :all question
...erDetails the same way, it says: undefined method `orderDetails'' for []:Array Have no clue what I''m doing wrong. Does just plain old find return something different than find :all? Here are my models: ----------------------------------- class Account < ActiveRecord::Base set_primary_key ''customerId'' has_many :addressbooks, :foreign_key => ''customerId'' has_many :orders, :foreign_key => ''customerId'' end class Addressbook < ActiveRecord::Base belongs_to :account end class Order < ActiveRecord::Base set_primary_key &q...
2006 Jun 19
3
Using set_primary_key breaks acts_as_tree with non-integer column
I just switched from using the standard "id" column into using my own primary key and generating my own unique id for each record. But, this breaks acts_as_tree. Because my new primary key is not an integer, it breaks the SQL query as follows: StatementInvalid in PagesController#create --------------------------------------------------------------------------------------
2006 Jan 03
4
Set the foreign key constraint column name?
I am applying Rails to an existing schema and not sure how much the existing developers will let me go in and rename things. So I need to discover the limits of what I can change with Rails. I''ve found set_table_name and set_primary_key, which have been very useful. If I have a "foo has_one :bar" relationship, but then in the bar table my column is named "fooid" or some other thing that is not "foo_id", is there a similar helper command I can use to change it? Everything''s working swimm...