similar to: Active record and multiple primary keys

Displaying 20 results from an estimated 200000 matches similar to: "Active record and multiple primary keys"

2011 Jun 27
2
insert value of primary key into another field before record is saved
Hey all, I created a seed task: def books! books = Book.where(:type_id => Type.find_by_name(''Fiction'')).order(''id'') books.each do |book| @books = 4.times.map do |i| subbook! "#{book.book_num}-#{i}".to_s, :book_state => BookState[:available].id, :book => book end end puts "log it:
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
2005 Dec 27
1
Legacy Data without Primary Keys
Hi all. I''m importing some legacy data via ActiveRecord. However, it has no primary key and I don''t want duplicates - I am reasonably sure the combination of two certain fields are unique, though. What''s the best practice & how''s it done pls? * Make a string id field and concatenate the two fields (or whatever I want for an ID) in it * Set the two
2005 Jun 29
3
Setting the value of a primary key field
I have a table that is to hold all ISO 639 language codes: alpha3t, alpha3b, alpha2, that bunch. It also (indirectly) holds language names, but that''s off-topic. alpha3t is the primary key, so I''ve told Active Record about this by saying set_primary_key "alpha3t" within the Language model. (Don''t try to call your models things like ISO639 (won''t work
2006 Aug 14
0
Composite Primary Keys - now works with Rails 1.1.6
Due to the foolish implied assumption that there''d never be a revision to activerecord library, the Composite Primary Key code promptly broke for anyone who updated their apps to Rails 1.1.6 (with its activerecord-1.14.4) Now the gem dependencies are fixed and your legacy databases are free to wield composite primary keys without fear again. Description: Composite Primary Keys
2006 Aug 02
0
Composite Primary Keys support for Associations
Announcement: Composite Primary Keys gem now includes support for ActiveRecord Associations. Summary: Composite Primary Keys allows an ActiveRecord to support 2+ primary keys using the set_primary_keys class method. Previous versions provided full CRUD and find support. This latest release provides support for more ActiveRecord magic: associations (has_many, belongs_to, etc) Full report:
2006 Jul 23
0
Composite Primary Keys 0.3.2
ActiveRecords with composite primary keys now seem to happily support find/create/update/destroy options. Url: http://compositekeys.rubyforge.org Background: Rails/ActiveRecords has long been critised for not supporting legacy databases, especially composite primary keys. This gem extends ARs with this support. Cheers Nic -- Posted via http://www.ruby-forum.com/.
2005 Jun 29
3
trouble with active record and sqlite
I am getting an error that I can''t figure out. I have a class called Test with 3 fields, id, x, and y. When I do Test.new(''x''=>1, ''y''=>2).save, I get an error saying that id (my ''not null primary key'') can''t be null. But isn''t active record supposed to deal with setting that for me? Here''s the code
2006 Apr 03
4
How to fake composite primary keys?
I know ActiveRecord doesn''t support composite primary keys, but I need to use one, and I need it ASAP. I don''t need any composite foreign keys, luckily; what I have is a table that stores old versions of rows in another table, so the composite key is an id + date stamp. Would someone tell me a hack I can use to support this? -- View this message in context:
2005 Jan 07
3
multicolumn primary keys in activerecord
hi, I''ve got the following tables in mysql notation: CREATE TABLE `nodes` ( `id` int(11) NOT NULL auto_increment, `parent_id` int(11) default ''0'', `group_id` int(11) default ''0'', PRIMARY KEY (`id`), ); CREATE TABLE `groups` ( `parent_id` int(11) NOT NULL default ''0'', `id` int(11) NOT NULL auto_increment,
2006 Nov 04
0
any recommendations for handling a non autoincrement primary key
Hey everyone, I''m working on an application that has a table with a nice natural primary key. Outside of the rails world it would be *the* primary key. I would prefer to use this natural primary key and define associations that use it. I''ve done so but the problem is that my form for entering a record in this table is currently failing. I''ve used
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 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
2006 Jul 18
1
usermonitor / user stamping active record
Quick question about userstamping records in a similar way to timestamping. There is an example of how this might work at: http://wiki.rubyonrails.org/rails/pages/Howto+Add+created_by+and+updated_by/versions/7 This seems to work fine on my development system. However, I am not sure how the User.current_user method, which is required, can guarantee to return the correct user since this is a
2006 Feb 28
0
ActiveRecord: Legacy primary keys
Hi, I''m building a frontend for a legacy schema, with tables like this: CREATE TABLE `types` ( `a_type_cd` varchar(6) NOT NULL default '''', `a_type` varchar(30) NOT NULL default '''', PRIMARY KEY (`a_type_cd`) ); The primary key is specified by the user (not auto-generated), and needs to be updateable. I create the following a base class to
2008 Sep 23
0
Questions on Active Record SQL type Finders & Dynamic Finder
Hi, I understand there are total 11 types of key Options for finding a record. The all 11 valid keys for the options hash are :conditions, :include, :order, :select, :group, :joins, :from, :limit, :offset, :readonly, and :lock. We also have Dynamic Finders for the same. e.g. ... find_by etc... I would like to know, how many types of dynamic finders, Active Record provides, to match all those
2006 Jan 03
2
Using multiple columns as primary key
Hi! I''m trying to use a primary key made up of two columns in my model''s table. But looking at the docs, it looks like ActiveRecord only supports using one field as primary key. Can anyone point me in a direction of this or verify that it''s not supported? Greetings, Gitte Wange
2006 Mar 07
13
Active Record - Can''t figure out relationship.
I have the following two tables: create table teams ( id int not null auto_increment, short_name varchar(12) not null, long_name varchar(50) not null, logo varchar(20) not null, primary key (id) ); create table rounds ( id int not null auto_increment, home_team_id int not null, away_team_id int
2006 Jan 04
4
many to many link table compound primary key explosion
Hi, I have a many-to-many relationship between two tables, questions and answers. My MySQL schema for the link table creates a primary key from the two fields to prevent duplicate records. When I add the same answer to the same question more than once, rails attempts to create a duplicate record and explodes with a MySQL error: MysqlError: Duplicate entry ''3-3'' for key 1:
2008 Jul 05
5
Does RSpec work nicely with UUID primary keys?
I have my application happily generating UUID primary keys using the uuidtools gem. But the auto-generated specifications created by "script/generate rspec_scaffold...", etc, assume that one is using a sequential integer primary key. For those who have hit this same issue, is it just a matter of rewriting the auto-generated specifications to take this into account, or does one have to