similar to: has_many with nullable foreign_key?

Displaying 20 results from an estimated 7000 matches similar to: "has_many with nullable foreign_key?"

2006 May 05
0
Missing documentation for find_in_collection? Trying to drill down in a 4 level has_many association fails
I''ve been reading up in ActiveRecord::Associations and playing around with my app via the console and found some interesting methods via the code completion of IRB, but I have no idea how to use them and can only find one hint in the API http://api.rubyonrails.com/classes/ActiveRecord/Associations/ ClassMethods.html It mentions here in the has many associations that if you use the
2006 Apr 04
1
has_many fails where find_by_sql succeeds
Can anyone explain why the method form of the following works, but the (apparently identical) has_many fails? I have 3 sites in my fixtures. Initially, for a new StockGroup, sites_not_using_this_stock_group should return all 3 sites (which it does). When you add a site to the StockGroup, it should disappear from the output of sites_not_using_this_stock_group. But the has_many form
2006 May 23
7
self-referencing has_many
Having a devil of a time finding records in a self-referencing has_many table relationship. Everything is working find looking at the has_many and the belongs_to relationship. But, when I try to find all "orphans", records that are neither a parent nor a child, I can not find a query that work in ActiveRecord. This query works in MySQL: SELECT * FROM templates LEFT JOIN templates
2005 Dec 27
0
How do I combine :finder_sql and :conditions to perform a sub-search on a custom has_many relationship?
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
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 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
2007 Feb 08
3
Get categories where forum-user posted in
I''m developing a system similar to the ForumExample (http:// wiki.rubyonrails.org/rails/pages/ForumExample), and stumbled upon the following. Let''s say I wanted to get all the categories a certain user posted in. How do I get that information withouth using a custom query through :finder_sql (and thus losing the find_in_collection ownage)? It would also be great to see how many
2010 Jan 25
0
has_many, :finder_sql, setting attributes
Hi all, My question is somewhat complicated, but bear with me. My project has a number of models: User, Program, and Team. Users belong to multiple Programs. Programs have multiple teams, but Teams belong to one program. For each Program a User belongs to, he can belong to multiple Teams. (Think of this in an athletic context where users are athletes, programs are universities). So my
2006 Jan 19
7
bug in has_many count?
I can submit a patch, but wanted to confirm I''m looking at this right... The docs indicate that if you specify a has_many association with :finder_sql, but no :counter_sql, it constructs the appropriate counter sql by substituting the SELECT clause. But has_many_association.rb doesn''t seem to do that -- it just passes Base#count_by_sql the finder_sql, which doesn''t
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
2006 Jan 06
1
has_many with :finder_sql question
hi all, I have a Class, Client, which has_many projects (Project class). the projects depend on a session_id variable, however. So the question is, how can I do the following: has_many :projects, :finder_sql => "SELECT p.* FROM projects p INNER JOIN projects_users pu ON pu.project_id = p.id WHERE pu.user_id = #{session[:user_id]}" The problem is that I need to filter a
2006 Jun 09
1
finder_sql issue with has_many :through
I have an inner join query that Action Record can''t seem to pull off conventionally, so I''m trying to use :finder_sql to utilize an sql query that works beautifully in SQL. The problem is, when I try to call the method, I get the following: private method `gsub'' called for #<Array:0x267de04> Here is my has_many code: has_many :mod_privileges,
2006 Jul 24
1
has_many + finder_sql
from the api I got: <pre> has_many :subscribers, :class_name => "Person", :finder_sql => ''SELECT DISTINCT people.* '' + ''FROM people p, post_subscriptions ps '' + ''WHERE ps.post_id = #{id} AND ps.person_id = p.id '' + ''ORDER BY p.first_name'' </pre> I would like to pass in the
2006 Aug 13
4
has_many and foreign_key question
Alright, noob here, etc. etc. Trying to figure out the has_many usage. If I understand correctly, when you declare that a table/class has_many whatevers, the rails assumption is that there will be a foreign key in the whatevers table pointing back to the ''id'' primary key in the first table. This doesn''t seem to be the only way to have a ''has_many''
2005 Nov 25
2
acts_as_list with 2 fields in the scope
Hi Railers, I''ve got a Categories table. I want it to act as a list within the scope of the parent_id AND the site_id. Categories table : id label site_id parent_id So, in my Category class, I have : acts_as_list :scope => ''site_id = #{site_id} AND parent_id = # {parent_id}'' The problem is that when I try to move_up a Category with a parent_id that is null,
2008 Oct 16
1
merge/combine data
Hi, I have the following data imported from a csv file user_id site_id name 1 1 11 februari 2 1 11 redbook 3 1 11 tips 7 3 6 sleep 8 3 6 monitoring 9 3 6 alarm Which I would like to merge/combine into user_id site_id name 1 1 11 februari,
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
2005 Jul 12
4
Calculation of group summaries
I know R has a steep learning curve, but from where I stand the slope looks like a sheer cliff. I'm pawing through the available docs and have come across examples which come close to what I want but are proving difficult for me to modify for my use. Calculating simple group means is fairly straight forward: data(PlantGrowth) attach(PlantGrowth) stack(mean(unstack(PlantGrowth)))
2006 Feb 13
0
has_many finder_sql #{id} single/double quotes voodoo
I never would have figured this out in many moons: has_many :subscribers, :class_name => "Person", :finder_sql => ''SELECT DISTINCT people.* '' + ''FROM people p, post_subscriptions ps '' + ''WHERE ps.post_id = #{id} AND ps.person_id = p.id '' + ''ORDER BY p.first_name'' Variable
2011 Sep 27
0
has_many with :finder_sql returns [nil]?
Is it supposed to do that? I find it very confusing. AR 3.0.10 class Unit has_many :units, :finder_sql => proc { "SELECT * FROM `#{table_name}` WHERE `location_id`=#{id} AND `location_type`=#{Location::UNIT}" } end Both should return []. However... >> Unit.first.units.find([1000000]) [2011-09-27 10:05:11|main|debug] Unit Load (4.0ms) SELECT `units`.* FROM `units`