similar to: How to set foreignkey in such a situation?

Displaying 20 results from an estimated 2000 matches similar to: "How to set foreignkey in such a situation?"

2006 Mar 14
4
has_one
I''ve got an order model that stores order data. One piece of data is a credit card type, which is a digit 1,2 or 3. I have a cardType model that has an id, shortName and LongName for the credit card merchant (visa, mastercard, amex). I want to be able to say: order.cardType.shortName, but can''t seem to get has_one working. It works with has_many and a finder_sql statement on
2005 Dec 27
3
Trouble combining :has_many, :finder_sql and :conditions to create a sub-search
I''m sure there''s something right under my nose that I''m missing. I have two tables with two parallel one-to-many relationships. I wish to use the :finder_sql parameter to essentially ''or'' the two foreign keys. What isn''t working for me is performing a ''sub-search''. Let''s say the tables are "stores" and
2006 Feb 14
6
[newb] Find vs Find :all question
I''m playing out with writing an online store. So far it has accounts, addressbooks, and orders, and those 3 are tied together with an customer ID. I also have orderDetails, which are associated to the order via an order number. See models below... When I do the following I can access the orderDetails information just fine: @order = Order.find(params[:id]) # i pass it a customer
2005 Apr 27
4
has_many syntax
Hi all, I have the following inside of an AR class definition: relationships=ActiveRecord::Base.connection.select_all(my_relationships_sql) relationships.each do |relationship| has_many RelatedItems, :class_name => relationship[''RelatedClass''], :foreign_key => relationship[''ForeignKey''] end This kind of works, but how can I assign the name of the
2006 Jan 17
15
legacy database and finder_sql nightmare!
This is my first rails app with a legacy database and I''m having a terrible time getting the models set up correctly. I have an order table that has a primary field named order_number. I have a name table with a primary of item_number. These two tables are liked by the item_number and the order_number, but not as you might think. If the order_number is 2500, then each entry in
2005 Dec 30
5
HABTM with finder_sql problem (Rails bug?)
I''m building an app that needs i18n support across the entire database (i.e. localized attributes). In order to do this I''ve created a special HABTM join table that can be associated with _any_ other table: create table language_strings ( for_table varchar(255) not null, foreign_id int not null, language_id varchar(5) not null, attr_name varchar(255) not null, value text
2006 Jun 16
3
Does HABTM support non "id" FKs?
Quick question. Say I have a geographical database with counties and zip codes where counties have and belong to many zip codes. zip_codes (id, zip_code) counties (id, name) When I create the association table, the Rails way says to do the following: counties_zip_codes (county_id, zip_code_id). However, given that zip_codes.zip_code is itself a candidate key, I would much prefer to do the
2006 Mar 06
2
is "alias" reserved?
I''m playing with an online store.... I have an orders table which holds orders (pricing, statuses, etc). An orderDetails table which holds detailed line items (itemNumbers, unit prices, etc). Each order can have multiple shipping addresses, so I also have an addressbook table. Each orderDetail is tied to an addressbook entry via the ordernumber and addressbook alias, but this
2006 Feb 23
3
Unable to update database object
This is really strange - hopefully someone out there may have seen behavior like this before. I have a user successfully created in the Users table of my application. When I try to update a single column using: @user = User.find(:first, :conditions => ["login_name = ?", @login_user.login_name]) @user.new_cookie_key @user.save I get the error:
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 May 11
1
RoR completely ignoring a column when saving changes
I have an action that needs to update two models/two tables in one shot, and it works great, but ignores one column. Here is the action code: (verify_id is irrelevant in this case) [CODE] def edit @page_title = "Edit User" @page_active_3 = "active" if request.post? @user = User.find(params[:id]) @profile = @user.profile verify_id(@user.id,
2006 Aug 15
2
has_many + finder_sql & :include
Hello, In a model I have: has_many :things, :finder_sql => '' select * from other_things '' + '' where id = #{id} '' When I do MyClass.find(:all, :include => :things) I get a weird error: from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract_adapter.rb:120:in
2006 Nov 02
4
Still Having Problems With :through When Going To Same Table... Help... please :-(
I am having a problem with doing a :through that goes back to the same table. The following are my two classes: >>>>> class User < ActiveRecord::Base has_many :spanks has_many :spanked, :through => :spanks, :source => :spanked_user has_many :was_spanked_by, :through => :spanks, :source => :user end class Spank < ActiveRecord::Base belongs_to :spanker,
2007 Apr 25
2
form_remote_for, reloaded
Hi, being relativly new to RoR, I''m having a problem which I found described in this forum and somewhere else - but with no solution. I know, that it may be bad to mix table and form tags, but the first solution of an in place editing within a table looked nice: Version using form_for: <tr> <%form_for :time_record, :url => { :action => "add_time_record" } do
2014 Jun 23
1
-h, --help option
Hi, tmux author refuses to add -h, --help option, because OpenSSH does not have it [1]. I don't see why convenience features of tmux should depend on OpenSSH, but because I have no other choice (and got curious) I ask here - why OpenSSH doesn't provide -h or --help option? I use PuTTY as my client, which processes --help option, and for `ssh` binary I usually use Google + StackOverflow.
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 Mar 31
3
Complex Through Statement
Quick Overview: I have an ''Employee'', some ''Merchants'' and some ''Products''. A ''Merchant'' has many ''Products''. An ''Employee'' has multiple ''Merchants'', depending on their relationship. For example, the Employee may be the enrollment contact for one merchant and the
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 Aug 02
2
Self-Referential has_many :through
Hello all. I am trying to create a self-referential has_many :through. I used the following site as a guide http://blog.hasmanythrough.com/articles/2006/04/21/self-referential-through but it still doesn''t appear to be working. I have two models. Person and Relationship. A person has many contacts (Which is another person) through relationships class Person < ActiveRecord::Base
2010 Nov 09
2
Undefined method
I am very new to ROR. (Ruby 1.8.7, rails 2.1.1, rack 0.8.7, mysql 5.1.41) I has my_app/lib/migration_helpers.rb file: module MigrationHelpers def self.foreign_key(from_table, from_column, to_table) constraint_name = "fk_#{from_table}_#{to_table}" execute %{alter table #{from_table} add constraint #{constraint_name} foreign key (#{from_column})