search for: primary_key

Displaying 20 results from an estimated 112 matches for "primary_key".

2006 Feb 28
0
ActiveRecord: Legacy primary keys
...update" method. (It is overridden so that you can update the primary key) - Is overriding self.inherited a good idea? - This implementation works for me, are there any other features anyone can think of that they may require in this instance? Usage: class AType < UserPKActiveRecord set_primary_key ''a_type_cd'' end Base Class: class UserPKActiveRecord < ActiveRecord::Base def self.inherited(sub) set_table_name undecorated_table_name(sub) self.class_eval <<-EOS def initialize params = nil super self.id = params[self.class.primary_key] i...
2006 Apr 02
5
adding primary_key to join table using migrations
...odel (because I want to add a "description" column as well so users can describe the tag. I''m not sure how to add this using migrations. Here is what I have: class AddNotesToTags < ActiveRecord::Migration def self.up add_column :tags_questions_users, "id", :primary_key add_column :tags_questions_users, "description", :string, :limit => 80, :null => false end def self.down remove_column :tags_questions_users, "id" remove_column :tags_questions_users, "description" end end That''s giving me this...
2010 Jun 16
2
class methods from module where active rec is involved
I have a module as shown below and when I extend an active record to use it, I can not access the primary_key method. In a simple test program using a similar approach where active record is not involved, access to the class methods seems to work ok. What can I do to make this work or so that I can access the class methods ? ################################## require ''active_record''...
2008 Sep 17
0
permalink_fu and classes with different primary_key than id?
Has anyone else had problems with this scenario? class Team < ActiveRecord::Base # Primary key self.primary_key = ''team_id'' has_many :players, :foreign_key => :team_id has_permalink :city, :param => true end I am getting all kinds of trouble - that goes away if I comment out the has_permalink declaration. With PermalinkFu: >> fs = Team.new => #<Team team_id: nil,...
2006 Mar 12
5
AR - Migrations - how to use a varchar as primary key instead of int ?
Hi I''d like to have a varchar primary key named id instead of the default int id. Does anyone knows how to specify this from migrations ? Should I also specify something in the model class ? thanks! Thibaut -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060312/797bca4b/attachment.html
2006 Apr 04
5
How to implement tag clouds using plugin?
...ts_as_taggable plugin?thanks! btw:the code above uses the tag_count method,which is defined in the gem: def tags_count(options = {}) options = {:order => ''count DESC''}.merge(options) o, t, o_pk, o_fk, t_pk, t_fk = table_name, tag_model.table_name, primary_key, taggable_foreign_key, tag_model.primary_key, tag_foreign_key jt = tags_join_model ? tags_join_model.table_name : tags_join_table sql = "SELECT #{t}.#{t_pk} AS id, #{t}.name AS name, COUNT(*) AS count FROM #{jt}, #{o}, #{t} WHERE #{jt}.#{t_fk} = #{t}.#{t_pk}...
2009 Sep 28
5
Multi-databases support
Hi, While I was hacking ovirt-server, I have found that it's currently restricted to Postgres DB. Even if I like postgres for serious work on a server, I really prefer to hack/dev locally on a Sqlite or MySQL DB. I have googled on rails in order to find a good answer for the "foreign key problem" which forces OVirt to stay on pg. I have found a plugin on this particular
2006 Apr 07
4
How to generate mapping with migration
Hi there, I''ve tried to add a m:n mapping table using the migration mechanism. ruby script\generate migration add_categories_notes_mapping and filled the migration file with: class AddNotesCategoriesMapping < ActiveRecord::Migration def self.up create_table :categories_notes do |t| t.column :category_id, :integer, :null=>false t.column :note_id, :integer,
2006 Dec 01
1
cannot use acts_as_ferret on legacy tables or tables with a
when i used "find_by_contents" on a legacy table with a different primary_key than "id" i always got results=nil even when total_hits was > 0 as a quick fix i changed line 261 in "class_methods.rb" from: conditions = [ "#{self.table_name}.id in (?)", id_array ] to: conditions = [ "#{self.table_name}.#{self.primary_key} in (?)"...
2006 Jan 06
0
bug rails activerecord association join
...eflection.macro when :has_and_belongs_to_many " LEFT OUTER JOIN #{reflection.options[:join_table]} ON " + "#{reflection.options[:join_table]}.#{reflection.options[:foreign_key] || to_s.foreign_key} = " + "#{table_name}.#{primary_key} " + " LEFT OUTER JOIN #{reflection.klass.table_name} ON " + "#{reflection.options[:join_table]}.#{reflection.options[:association_foreign_key] || reflection.klass.to_s.foreign_key} = " + "#{reflection.klass.table_name}.#{refle...
2013 Feb 26
4
3 models, joining and nested queries
I have 3 models, class Host ref: string address: string, name: string primary_key=''ref'' has_many :rooms, :class_name=>"Room", :foreign_key=>''host_ref'' Class Room ref :string host_ref: string capacity: integer primary_key=''ref'' has_many :bookings, :class_nam...
2010 Aug 19
1
Composite primary keys and :joins=>
...PKs are type_key and code_key, there is no id col and I cannot alter this db Table-B: # each row has only the code as a foreign_key, the type_key is hard-coded to "FOOKEY" an_id, code, ... Models: class TableB < AR::Base set_table_name ''table_b'' set_primary_key :an_id # singular PK belongs_to :code_name, :class_name=>''TableA'', :primary_key=>:pk_code_name, :foreign_key=>:code SELECT = "*, table_a.name AS pk_name" def self.get_all all(:select=>SELECT, :joins=>:code_name) end end cla...
2006 Aug 02
2
mangle ActiveRecord
...ey_id, session_id etc columns that I use on basically all tables. It would not be DRY to repeat this on all my migrations. I figured module ActiveRecord::ConnectionAdapters::SchemaStatements def create_table(name, options={}) table_definition = TableDefinition.new(self) table_definition.primary_key(options[:primary_key] || "id") unless options[:id] == false table_definition.column(:obj , :bigint ) unless options[:obj] == false table_definition.column(:session_id, :bigint ) unless options[:session] == false table_definition.column(:created_at, :datetime) u...
2006 Oct 31
4
Auto-increment lost during migration.
Hi. I get some strange results when using rename_column on a primary key in a migration. It seems like the migration script removes the auto-increment property if you rename a column. This is a minimal example. create_table :foo, :primary_key => :foo_id do |t| t.column "name", :string end # renaming the primary key makes auto-increment disappear. rename_column :foo, :foo_id, :bar_id Is this a known problem, any beautiful solution available? Maybe use change_column instead? Best regards, Tobias Nurmirant...
2004 Nov 22
0
Can''t set then read id on AR class in 0.8.5
...ag is reached. This means that child elements get saved before the parent. When the child element is created it''s belongs_to relationship is set to the parent object. I came across a problem when upgrading from 0.8.0 to 0.8.5, which changed: def id read_attribute(self.class.primary_key) end to def id read_attribute(self.class.primary_key) unless new_record? end (Ticket 187) As the parent record hasn''t been saved yet, when I call #save on the child it can''t get the ID of the parent to insert into the foreign key field. I''ve...
2009 May 01
1
how to disable auto-increment in primary key.
How can i disable the auto-increment for a primary key data type. The purpose of using primary_key data type is using different name for primary key. But we still want to use all the properties of "id" except for auto increment part. I had my migration as following #=============MIGRATION def self.up create_table :pk2s , :id=> false do |t| t.primary_key :uid t.stri...
2005 Dec 17
4
Rake migrate and creating join tables
...is that when you run this code, there''s no primary key generated on the table. I''ve looked through the source code, and noticed that the code doesn''t even attempt to create a primary key unless :id => true, so I tried: create_table "apples_oranges", :primary_key => "apple_id, orange_id", :force => true do |t| But that didn''t work -- it tried to create a column called "apple_id, orange_id" -- not at all what I wanted. I also tried the :primary_key type for the columns, but that didn''t work, either (not that I...
2006 May 14
3
Strange Database Mapping Question
...pplication for the staff at my office to play a form of virtual Super14. Its a bit like any of the virtual sports available on the internet except this one is for Rugby. The relevant tables in my database are as follows: create table teams ( id INT AUTO_INCREMENT NOT NULL, name VARCHAR(40), PRIMARY_KEY(id) ); create table games ( id INT AUTO_INCREMENT NOT NULL, date DATETIME, #Date of game home_teams_id INT, #id of home team away_teams_id INT, #id of away team home_team_score INT, #this is not meant to link to another table away_team_score INT, #this is not meant to link to another table...
2006 Jan 04
3
Legacy Table works-except edit?
Greetings, I''m trying to put a Rails face on a Legacy Oracle 10 table. I am currently setting the table_name and primary_key, and I get the list and show to work fine. However, when I hit edit I just get the Editing <table name>, Edit button, Show, and Back. None of the fields are rendered. Why would I be able to show these fields in the show and list, but not edit them in the edit? My DB user has the power to...
2006 Jul 12
1
Dumping schema
All, It looks like rake db:schema:dump does not dump primary keys. I have some legacy table that don''t follow the convention ie pk = id and none of the primary keys for these tables are getting dumped... Seems strange as this should be readily available from the db. I am using MySQL. Is anybody else seeing that ? Incidentally how does one specify a primary key using