Displaying 20 results from an estimated 100000 matches similar to: "start primary key id > 1"
2008 Jan 21
13
has_many with different primary key
I''ve got quite the ActiveRecord challenge, any help would be
appreciated.
In my current project Companies can have many reviews.
class Company < ActiveRecord::Base
has_many :reviews, :as => :reviewable
end
However, my company table, I have two different IDs to identify my
company.
id - This is the typical id we use for normal stuff
other_company_id - This is the id we use
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 Oct 09
2
Multi-column primary key in joining tables
Folks,
What is the convention for primary key fields in joining tables in RoR?
I have a model representing a joining table, and I can''t seem to
prevent ActiveRecord''s find method from looking for an id column. I
don''t have an auto-incremented field in my table (happy to add one if
that is the convention), and therefore my primary key is the
combination of the 2 foreign
2007 Aug 30
1
belongs_to with foreign keys that reference non primary key columns
Hello,
I have a situation where the foreign key into a table doesn''t
correspond to that table''s primary key:
my_table
-------------
id (pk)
name
...
other_table
--------------
id (pk)
my_table_name (fk references my_table(name))
...
I want to be able to say something like:
class OtherTable < ActiveRecord::Base
belongs_to :my_table, :foreign_key => { :my_table_name
2007 Oct 16
2
Primary Keys enforcement vanishes in test database
I use this naming convention for primary keys:
ActiveRecord::Base.primary_key_prefix_type
= :table_name_with_underscore
I generate the MySQL test database: rake db:test:prepare, and although
the column is there there is no primary key enforcement/index and no
autoincrement (so activerecord saves fail). Is this a bug? What is
the best workaround?
Alan
2008 Apr 18
3
has_many and belongs_to with non-primary foreign keys
Hi,
I''m having a bit of trouble with my first Rails app.
----
I have two tables:
create_table :items do |t|
t.column :created_at, :timestamp
t.column :user_id, :int
t.column :text, :text
end
create_table :users do |t|
t.column :user_id, :int
t.column :name, :string
end
----
I''m trying to use the "user_id" field to link both tables, with each
user
2007 Aug 23
6
Saving ActiveRecord in PostgreSQL without id
I have a small table that is used to temporarily queue requests, as such
it does not have an id field (or any other primary key), because it
doesn''t make sense to have one.
When I created an ActiveRecord class and tried to save it, I get:
ActiveRecord::StatementInvalid: PGError: ERROR: relation
"temp_requests_id_seq" does not exist
It keeps looking for the id to auto
2006 Nov 07
4
Unknown column 'id' in 'field list
Hello,
I''m trying to write a unit test for model that doesn''t have an ''id''
field. I created the model''s table with the following migration, making
sure the primary key was set.
class CreateActiveUserMetrics < ActiveRecord::Migration
def self.up
create_table :active_user_metrics,
{:id => false,
2009 Mar 09
3
multiple columns primary key
Hi all,
I have two tables:
TABLE 1
A pk - fk (referencesc TABLE 2)
B pk
C pk
D pk
E
F
TABLE 2
A pk
G
H
I
L
I don''t use incremental field (id). I''d like don''t use find_by_sql.
How can I define both models to use correctly find method (with
include)? With only one column primary key I haven''t problems.
I thought two solutions, but I don''t like these
2007 Jun 21
11
one-to-one, compound primary key, naming conventions
My understanding is that, given tables Alpha and Beta that the table
which holds the 1-to-1 relation will be called Alpha_Beta (or is it
alpha_beta?). So far so good.
alpha_beta will have, lets say, two fields: alpha_id and beta_id. Seems
that it''d be a good idea for those two fields to form a compound primary
key, ensuring there are no duplicates.
However, RoR doesn''t
2009 Mar 25
6
Hash with key and value from ActiveRecord?
Heya,
I think I have thinking barrier. I just want a simple hash out of an
ActiveRecord.
@attributes = Attribute.find_all_by_character_id(@character).hash {
|u| [u.name, u.value] }
and I would like to access it like
@attributes[:health]
but it doesn''t work. Anyone can help me out with that?
--
Posted via http://www.ruby-forum.com/.
2007 Jul 18
1
Truncate table to reset id back to 1
What im using now is ActiveRecord::Base.connection.execute(''TRUNCATE
table_products'') to reset the id back to 1. Is there another way without
using direct sql command to reset the id back to 1?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on
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
2009 Feb 24
4
Cannot pass id field to ActiveRecord
Dear all
I have a dummy question. The model code as follow:
class User < ActiveRecord::Base
set_primary_key "username"
end
In script/console
user = {:username => "123", :display_name => "345"}
=> {:username=>"123", :display_name=>"345"}
a = User.new(user)
=> #<User username: nil, display_name: "345">
2008 Mar 29
3
primary key?
can you use 2 pirmary keys.
the standard user_id key exists but i would also like to use another
key for my links. i am not sure how to implement this. also i don''t
want any auto incrementing of this second primary key that i would
like to use for my relationships.
if there is a good db, model, relationship tutorial out there i would
love to know about it.
2009 Mar 07
0
Be careful of BIGINT primary key fields in MySQL. Will cause problems with ActiveRecord create (but not find)
The MySQL/Ruby library doesn''t properly handle inserts into tables
with the primary key being a BIGINT
If the ID returned to the MySQL/Ruby library is LARGER than the INT
range, the value is returned to Ruby truncated and incorrect. This is
then passed up to ActiveRecord and into the id field of your model.
The actual INSERT worked properly and when do you an ActiveRecord find
for the
2007 Mar 08
2
Composite Primary Keys
Have been looking into using rails but am finding the "Composite
Primary Keys are Bad" thing a tad disturbing (to put it mildly). I
have been working with RDBMS systems for over fifteen years and this
is the first time I have herd the idea questioned. I have cone across
using surrogate keys which mirror the composite key for performance
reasons in VERY big databases but I have never
2007 Sep 03
7
relationing has_many, belongs_to
Hello, i want to know if i am relationing fine, because i am having
problems,i have 2 models, one for members and other to relate some
members to this:
class Member < ActiveRecord::Base
has_many :matrix, :foreign_key=>:parent
end
class Matrix < ActiveRecord::Base
set_table_name :matrix
set_primary_key :userid
belongs_to :member, :foreign_key=>:userid
acts_as_tree
2009 Apr 11
6
Inserting data from 1 table to another by using find_by_sql
Hi All,
I am inserting data from one table to another by using following method
@data=RoyaltyReportFiles.find_by_sql("insert into royalty_reports
(artist_name, album_name) select artist_name, album_name from
temp_royalty_reports where id=328417")
it saves the data into royalty_reports table but it gives following
error and application crashes. i am using rails 1.2.5
You have a nil
2009 Feb 02
2
looking for help with NoMethodError: undefined method `key?' for #<String:0x4795488>
Hi all,
Any help with this would be appreciated. I''m using instant rails,
updated to 2.2.2, on Windows XP.
I''ve created my DB and scaffolded a few things and put some fixtures
into place, and when I run the tests I get many errors that look like
this:
---------------------------------
1) Error:
test_the_truth(EntityTest):
NoMethodError: undefined method `key?'' for