similar to: has_one & foreign_key - generating bad SQL

Displaying 20 results from an estimated 20000 matches similar to: "has_one & foreign_key - generating bad SQL"

2012 Nov 19
0
has_one :through NoMethodError: undefined method `klass' for nil:NilClass when doing class_name on reflection
Not sure if this is expected or not. Only happened with a has_one :through I had setup. (Workaround is just to remove it and go through the association manually vs has_one ..., through: .) Not a big deal if no one has time to look at it, as it''s not a big enough deal to look into a fix on our side. In Rails (3.2.9) console if I do: MyModel.reflections.each {|name,reflection|
2008 Feb 28
2
REST nested routes with has_one
Hi everyone, I have 2 models: class User < ActiveRecord::Base has_one :laboratory, :foreign_key => "pi_id" end class Laboratory < ActiveRecord::Base belongs_to :pi, :class_name => "User", :foreign_key => "pi_id" end I set the following routes (in routes.rb): map.resources :laboratories map.resources :users, :has_one => :laboratory All the
2006 Jan 06
0
bug rails activerecord association join
hi, I found a bug in ActiveRecord association SQL INNER JOIN codes. in has_many, has_one, habtm and belongs_to queries the foreign key is determined from the table name of reflection and self. but that''s worng because if you use a global prefix or suffix for your tables the foreign keys will be in format of PREFIX_CLASSNAME_SUFFIX_id which is wrong, because it breaks the advantage of
2006 Jul 01
0
activerecord generating wrong syntax with postgresql
I''m using activerecord outside of rails and find_first generates sql that postgresql doesnt'' like. This is rails 1.1.4, with everything up to date via "gem update". This is the command line: ruby -rrubygems seca -c ../etc/seca.cnf cert --export 1 --format pkcs12 --key root.key >root.pfx This is the error: (PGError: ERROR: argument of WHERE must be type
2008 Sep 29
1
has_one :through with :source. How to alias association?
Hi to everyone, I have the following models: class Attachment < ActiveRecord::Base has_attachment :content_type => [:image, ''application/pdf''], :max_size => 3.megabytes, :path_prefix => ''../private/attachments'', :storage => :file_system, :processor => :rmagick,
2006 Apr 09
1
Join using :THROUGH - SQL is wrong even when using :SOURCE
Here''s a join table for an educational institution: create_table "student_appointments", :force => true do |t| t.column "supervisor_id", :integer, :default => 0, :null => false t.column "student_id", :integer, :default => 0, :null => false t.column "course_id", :integer, :default => 0, :null => false [other columns
2006 Feb 02
1
circular table refs in activerecord
I cannot find this anywhere, and it is holding up a project. I have a *very* simple rails app with three tables, one of which is the users table: users: Column | Type | Modifiers ---------------+-----------------------------+----------------- id | integer | not null default nextval(''public.users_id_seq''::text) login
2008 Feb 19
0
Issue with Observers and has_one association...
Hey Guys, I''m getting a peculiar bug working with Observers and has_one associations. When a has_one association is invoked by an Observer it always returns null. I looked in the development.log file and the SQL for the has_one association isn''t even being executed. On the other hand, when I replace the has_one association with just a hand crafted method, it does get called
2006 Jul 26
8
team captain - habtm w/has_one...
the below... class User < ActiveRecord::Base has_and_belongs_to_many :teams class Team < ActiveRecord::Base has_and_belongs_to_many :users has_one :captain, :class_name => ''User'' produces the error... Mysql::Error: Unknown column ''users.team_id'' in ''where clause'': SELECT * FROM users WHERE (users.team_id = 1) LIMIT 1 i
2006 Jan 30
1
Multiple associations between tables - do they ever work?
This is really bugging me. How can I get a second association to work between 2 tables. I have two models, User and Article. A user has many articles, and an article belongs to one user. Then I have the "current article", which is a the article that the user is currently viewing/editing. I want to track/save this value, so they can come back to the same article if they log out
2005 Dec 19
0
has_one mapping with arbitrary right and left hand side keys
I have two tables: table_1: tab1_id, other_id table_2: id, tab2_id, something_else I would like to specify a has_one mapping from table_1 to table_2 but specifying that the join is based on (table_2.tab2_id = table_1.other_id). I am half way there with: class Table1 < ActiveRecord::Base set_table_name "table_1" set_primary_key "tab1_id" has_one :Table2, :class_name
2005 Oct 27
0
has_one with Single Table Inheritance - NameError : uninitialized constant
I am having a problem with using SIngle Table Inheritance with a has_one relationship, and I am at a loss of what could be causing it. Below is the related code and the error message. class User < ActiveRecord::Base has_one :wishlist end class List < ActiveRecord::Base belongs_to :user end class Wishlist < List has_and_belongs_to_many :items, :class_name =>
2006 Mar 03
6
has_one :next - invalid name?
I have this in a model: has_one :next, :class_name=>''WorkPart'', :foreign_key=>''next_id'' And it causes this error: compile error /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/deprecated_associations.rb:83: void value expression
2006 May 28
7
Self-referential has_many :through relationship
Hi, I have a self-referential has_many :through relationship setup to track relationships between users. Basically relationships are modeled as a join table with an extra column ''relation''. create table relationships ( user_id integer unsigned not null, friend_id integer unsigned not null, relation char(1) not null, ) --- relations --- f = friend r = request to
2006 Jan 06
2
Re: Some advice on DB modeling
I have more or less the same problem. I''m trying to build a system where users can enter their friends. But the solutions seems not to work for me. I used same sql: CREATE TABLE `friends` ( `user_id` int(11) NOT NULL default ''0'', `friend_id` int(11) NOT NULL default ''0'', KEY `user_id` (`user_id`), KEY `friend_id` (`friend_id`),
2006 Jul 15
3
How bad is it to have 7 joins in my find_by_sql?
My question is whether there''s a more idiomatic rails way of structuring this query or of redoing the underlying models. First, the ugly find_by_sql code, which is the method to generate an atom feed: def atom items_per_feed = 15 sql_query = "SELECT activities.*, users.real_name AS real_name, accounts.last_scraped_at AS last_scraped_at,
2006 Feb 27
4
2 belongs_to to the same parent table
Hello! I have 2 table: users and buddies User: id, name, ... Buddy: id, user_id, user_buddy_id, ... So if you have 2 users 1,jack and 2,fred and fred is a buddy of jack, there is a Buddy object: id=1, user_id=1, user_buddy_id=2 I can declare only one belongs_to in Buddy and one has_many in User. And there is conflict if I had the second one (the first one is discarded) class User has_many
2006 Mar 25
0
Self-Referential Many-To-Many relationships where the relationship itself has data.
Trying to model a bunch of users that have friends that are other users. clearly a job for has_and_belongs_to_many, but the trick is, they have ratings for their friends. I have gone through the Rails Recipes book, and it seems like I''m trying to combine the self-referential many-to-many recipe (12) and the many to many relationships where the relationship itself has data recipe (16). So
2006 Dec 07
2
Problem saving parent and children using belongs_to, class_name, and foreign_key
Hi, I have a real simple association setup here that''s just trying to: - Create a new PayjunctionOrder - Create some LineItem objects and assign them to the PayjunctionOrder - Save everything I''m using Rails Edge. ---- class PayjunctionOrder < ActiveRecord::Base has_many :line_items end ------------------ ---- class LineItem < ActiveRecord::Base belongs_to :order,
2009 Jun 20
0
[Rails 2.3] nested_attributes and validation of nested model
Hi, I''m using nested models to create form in my view. It looks like this: <% form_for :user, :url => {:action => "add_owner" }, :html => { :method => :post } do |u| %> <li><label>Name: </label><%= u.text_field :name %></li> <li><label>Surname: </label><%= u.text_field :surname %></li> <%