Displaying 20 results from an estimated 10000 matches similar to: "How specify foreign key column name in model?"
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 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"
2006 Apr 11
1
Foreign Keys
Hi,
My tables 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
2013 Jun 18
1
How to Pass Jquery selected dropdown values and radio button values to controller
Hi,
I have an advance search page and its code is as follows -
I have written my code like this
<div class="container">
<%= form_tag search_index_path, method: :get do %>
<%= radio_button_tag ''user_type'', ''customer'' %><p>Customer</p>
<%= radio_button_tag ''user_type'',
2006 Jan 11
3
How do you do a custom sql call in rails?
Hi.
I am developing an industry specific crm that allows busineses to track
customers in a particular way. Each customer will be assigned a customer
number. The first customer will have a customer number of 1, the second
customer_number = 2, etc... Note that this customer number is not global
but particular to the account that created the customer (see schema snip
below).
I need to have a
2009 Feb 21
2
Foreign-key confusion
Hi,
I am a bit confused about managing the relationship between two of my
tables:
I have developed a script using scRUBYt that scrapes data from a website
and dumps the following four fields into my Shows table:
class CreateShows
create table :shows do |t|
t.string :date
t.string :venue
t.string :info
t.string :comics
The second table I created is called Theatres:
class
2007 Sep 04
2
Use of uniqueidentifer type for primary key?
I''m working on a legacy SQL db. It is distributed, to they are using
the uniqueidentifier type for the primary key.
At first, at least, I won''t be updating records, but I''m seeing a lot
of negativity about using anything other than incrementing integers
for the pk--which are obviously inadequate for this environment.
It is enough to use set_primary_key? Do I need
2006 May 18
8
Concatenated key
Hi all,
I started playing a couple days ago with Rails and it find it very
interesting.
But I''m a bit stuck with making it work with a concatenated primary key.
I want to use my own names for the DB fields and I''m using SQL Server
2005.
My tables look roughly like this:
CREATE TABLE USERS (
USR_ID VARCHAR(25) NOT NULL PRIMARY KEY,
USR_PASS VARCHAR(25)
)
CREATE TABLE
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" =>
2006 Mar 15
1
Through method problems with custom foreign_keys
A person has a many company_branches and
A company_branch has many people.
This join is represented using a "contacts" table.
I am using a legacy schema so i am forced into using non-standard rails
primary keys. I am using the new through relationship in rails 1.1.
p=Person.find(1)
b=p.company_branches # gives this error:
ActiveRecord::StatementInvalid: OCIError: ORA-00904:
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/.
2007 Mar 01
1
PostgreSQL primary (sequence) key issue
Hi,
I have a sequence set up on one of my tables called seq_user_mytable. I
tried the following with no joy:
set_primary_key "user_id", :sequence => "seq_user_mytable" and:
ActiveRecord::Base.seq_user_mytable
again with no joy. How do I implement a sequence in Rails/ActiveRecord?
--
Regards
Andrew
--~--~---------~--~----~------------~-------~--~----~
You received this
2006 Jan 18
3
legacy database on remote host
I''m getting this error in webrick then it crashes leaving nothing in the
log.
ruby: symbol lookup error:
/usr/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.so: undefined symbol:
mysql_sqlstate
Here is the standard query I would normally write to get the data.
select * from child,parent
where CONCAT(SUBSTRING(child.item_number,1,14,''00'') =
parent.order_number and
2006 Jul 10
10
has_many :through and foreign key parameters
I just took my HABTM and turned it into a :through since my join table
has another "non-joiny" attribute.
I went from this:
has_many_and_belongs_to :jobs, :join_table => ''tablename'',
:foreign_key => ''x'',
:association_foreign_key => ''y''
to this:
has_many :jobs, :through =>
2006 Feb 03
3
My associations are coming out nil.
I''ve got a fairly simple system with a table for my Users that
includes a CountryId field which looks up to the CountryId field of my
Country table. What I would like to happen is for my Rails
application, 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
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
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
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 an alternate
primary key working?
Thanks,
Ken
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
2006 Jun 09
2
Support for clustered primary key in rails?
Hi, I need to support a legacy database that mostly uses clustered
primary keys (i.e. every primary key consiststs of multiple fields not
just a single one. E.g. if I have tables A,B and C and C depends on
tables A and B, then C''s primary key will consist of 3 or more fields-
the foreign key fields pointing to A and B and a field or fields from C
that will make C unique- in