search for: finder_sql

Displaying 20 results from an estimated 67 matches for "finder_sql".

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 work so good. def count(runtime_conditions = nil)...
2006 Feb 28
3
[AR] #{id} namespace visibility used in finder_sql
Dears, [Rails 1.0.0] I''m working with a legacy schema, and around my 20+ models i''ve used some AR constructs. They are based on a finder_sql doing some dirty sql and using #{id} from the ''pivot'' model for extracting data in other tables. like : class Division < ActiveRecord::Base set_table_name "legacy_division" set_primary_key "divid" set_sequence_name "SQ1_DIV" has_many :me...
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 "people," and the relationships are called "works_for" and "sh...
2006 Oct 30
2
It this possible: finder_sql-like behavior for belongs_to?
...''ve attached to code at the end of this email. Suffice it to say I need to use the standard "id" columns in most associations within the application, but for this particular MajicEmployee to GateClockEmployee relationship, I need to use two non-standard columns for joining. The :finder_sql option solves this problem for me on the has_many side, but belongs_to doesn''t seem to support :finder_sql (although I''ve included it in the below code to illustrate what I''m trying to do). Can anyone tell me how I can get the belongs_to side working so I can query from...
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 client''s projects using a session variable, and the :finder_sql produces the error: "undefined local vari...
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_adapter...
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, :finder_sql => [''SELECT assignm...
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 "people," and the relationships are called "works_for" and "sh...
2006 Jan 17
15
legacy database and finder_sql nightmare!
...ight think. If the order_number is 2500, then each entry in the name table will have it''s item number incremented by 1 (i.e. 2501,2501,2503). Here are my models class Order < ActiveRecord::Base set_table_name :order set_primary_key :order_number has_many :name, :finder_sql => ''SELECT * from name where name.item_number like CONCAT(SUBSTRING(#{order_number},1,14),\''%\'')'' end ~ class Name < ActiveRecord::Base set_table_name :name set_primary_key :item_number belongs_to :order, :finder_sq...
2010 Jan 25
0
has_many, :finder_sql, setting attributes
...belong to multiple Teams. (Think of this in an athletic context where users are athletes, programs are universities). So my models look something like this: class User < ActiveRecord::Base has_many :user_programs has_many :programs, :through => :user_programs has_many :user_teams, :finder_sql => ''SELECT ut.* FROM user_teams AS ut JOIN user_programs AS up ON up.user_program_id = ut.user_program_id JOIN users AS u ON up.user_id = u.user_id WHERE u.user_id =...
2006 Aug 13
1
Is :finder_sql using #{id} broken?
Hi All, It seems that :finder_sql in a HABTM association only interprets a single quoted #{id} the first time through a query. I see examples of this being used in a few places (though with has_many) and I don''t really see how to use :finder_sql without a #{id}. Am I missing something or is this just broken? -- Paul Ha...
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 the...
2007 Mar 21
1
Eager Loading with custom :finder_sql
Is there any way to do eager loading when using custom :finder_sql ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, se...
2007 Sep 06
1
finder_sql patch problem
Hello, I have the finder_sql problem and I found this patch http://dev.rubyonrails.org/ticket/7576; but I don''t know how to use this patch?? I copied all the changes into the correct files and restartet the server of my ruby on rails application, but nothing changed. Could someone tell me please how I have to use this...
2005 Dec 30
5
HABTM with finder_sql problem (Rails bug?)
...k I then add something like this to each models that needs it: class Property < ActiveRecord::Base has_and_belongs_to_many :names, :class_name => ''Language'', :join_table => ''language_strings'', :foreign_key => ''foreign_id'', :finder_sql => "SELECT language_id AS id, value " + "FROM language_strings " + "WHERE for_table = ''properties'' AND " + ''foreign_id = #{id} AND '' + "attr_name = ''name''" end ( With pretty highlighti...
2006 Mar 14
4
has_one
...s 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 it, but that returns an array, so I have to access it like this: order.cardTypes[0].shortName The has_one below doesn''t really work, because the sql query ends up looks something like this: select * from cardTypes where cardTypes.id = ''theprimarykeyfororder'&...
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 interpolation in *single* quotes? Put...
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` LIMIT 1...
2006 Mar 10
4
problem when looping through habtm children in a view
...pic are the same (the ones belonging to the first topic). In other words, I expect an SQL query to be run each time through the inner loop, and it is, but it is always using the same topic id (that of the first topic in the loop). The habtm for child_documents defined in my model uses a custom finder_sql which uses the id variable for the topic id. Could this somehow not be populated correctly? I can make the code work using other methods, but I''m wondering why this fails. Thanks. -- Posted via http://www.ruby-forum.com/.
2006 Dec 02
0
has_and_belongs_to_many and finder_sql options
Hello everybody, I''ve been hit by the bug described at http://dev.rubyonrails.org/ticket/1732 Is there any reason why the patch is still not included in trunk ? The patch seem simple enough. Regards, -- Damien Merenne http://blog.cosinux.org/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups