similar to: ActiveRecord's "conditions" magic

Displaying 20 results from an estimated 10000 matches similar to: "ActiveRecord's "conditions" magic"

2006 Apr 04
5
How to implement tag clouds using plugin?
The code on http://blog.craz8.com/articles/2005/10/28/acts_as_taggable-is-a-cool-piece-of-code is based on the acts_as_taggable gem,anybody has done that using the acts_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)
2008 Sep 17
13
Capturing the sql from a statement without executing it?
Hi guys, Is there an elegant way to capture the sql that would have been executed by an ActiveRecord statement, without actually executing it? :) I''m imagining something like sql = User.find(1).groups.to_sql or perhaps sql = ActiveRecord::Base.capture_sql { User.find(1).groups } resulting in sql = ''SELECT * FROM groups INNER JOIN memberships.... WHERE users.id =
2008 May 30
9
find_by_sql without a model? how to do this?
Hi, I''d like to do a "find_by_sql" without a model (e.g. <model name>.find_by_sql("...")) as the results I get back are a once off special, and I''m happy to handle them as an array. How do I do this? "ActiveRecord::Base.find_by_sql(...)" does not seem to work? Background - At the moment I''m doing within a model <model_name>,
2006 Apr 26
2
two layers of has_many
Hi, There are many companies. Each company has many departments. Each department has many employees. The following find_by_sql method seems awful. What is the best way to get all the employees of a company? class Company < ActiveRecord::Base has_many :departments def employees Employee.find_by_sql("SELECT employees.* FROM companies, departments, employees
2011 Dec 07
5
Find_by_sql help?
How to make it work with paginator (kaminari)? MySQL and full text search: Words (id, word) @words = Word.find_by_sql(["SELECT id, word, MATCH (word) AGAINST (?) AS Score FROM words WHERE MATCH (word) AGAINST (?) ORDER BY Score Desc, word!=?", params[:search],params[:search],params[:search]]) I can''t add .page(params[:page]).per(5) to the end of "find_by_sql()" so
2011 Aug 25
3
ActiveRecord searching in batch (with find_by_sql)
I have an issue where I am getting a large number of records from the database and I cant afford to keep it in the memory due to performance issues. Therefore using the following would be ideal, User.find_each(:batch_size => 5000, :start => 2000) do |user| NewsLetter.weekly_deliver(user) end however, I would like to use find_by_sql since my query is user defined. Question is, is it
2006 Dec 14
3
Problem with ActiveRecord and Associations
Hi, I''m having what I believe to be a typecast problem with ActiveRecord and Associations. In the code below, I need to flag a contact record for deletion if the contact doesn''t have any addresses or books records: sql = "select id, delete_flag from contacts where id = #{params[:id]}" contact = Contact.find_by_sql(sql) if (contact[0].addresses.count +
2006 Feb 02
3
What is best way to show only records belonging to logged user?
Hi all, What is best way to show only records belonging to logged user? I understand that it is better to handle this in model and not controller. I am thinking of intercepting find methods in model and add clause something like "WHERE id_user = #{user_id}". I would like to hear if you would do it likewise and if yes is it better to hack find_by_sql() or find() method? thanks in
2006 Mar 18
9
How do I write this SQL the Rails way?
I''m trying to find all the unique bill_number, status records in Bills table. I can do it with a find_by_sql statement like this: @records = Bill.find_by_sql( "select distinct bill_number, status from bills group by bill_number, status;") How would I rewrite it using ''find :all
2006 Jan 31
2
Relationship navigation issue
class Event < ActiveRecord::Base belongs_to :venue belongs_to :category end class Venue < ActiveRecord::Base belongs_to :city end class City < ActiveRecord::Base belongs_to :state end I want to retrieve all event records belonging to a state. Coming from hibernate background I tried something like this: def self.list_for_a_state(state_id) find_by_sql(["select e.*
2006 Jan 12
5
Question about using DISTINCT in ActiveRecord find method.
Hi, Am relatively new to the RoR world. My question is quite simple. I have a query like such: shipmentNumbers = Order.find_by_sql(["select distinct s.id from orders o, line_items li, shipment_lines sl, shipments s where o.number=? and o.id = li.order_id and li.id = sl.line_item_id and sl.shipment_id = s.id", number]) The above query works fine. I wanted to do the same query using
2006 Jun 07
10
habtm "AND" find conditions
I have two tables and a join table for them e.g. books, authors in a many to many relationship (habtm) and a join table books_authors. I can successfully search for a book that has "author.id = 2 OR author.id = 4" but I am unable to search for "author.id = 2 AND author.id = 4" This is because the result of all the joins only has one author.id column so no single row has
2006 Apr 19
3
newbie question : select distinct in model
Hi guys, I''m new so be gentle :-) How do I put the following into a method inside a model.... select distinct(pairing_id), description from pairings_stories, pairings where pairing_id = pairings.id order by description I basically want to have a @pairlist = Pairing.UniqueBookList line in a controller. Just not sure how to wire up this method in the model. And do I use
2004 Oct 05
1
QOS on each interface
I have a firewall with 3 interfaces DMZ, INTERNET, LAN. Does anyone have an example script to do QOS on multiple intefaces using htb? Gareth Segree mailto:Gareth.Segree@gleanerjm.com <mailto:Gareth.Segree@gleanerjm.com> Technical Support Analyst The Gleaner Company Ltd. 7 North Street Kingston Tel: 922-3400
2006 May 05
1
Help with ActiveRecord
Model: class AdminQueue < ActiveRecord::Base set_table_name ''adminqueue'' end Interacting with it in script/console >> AdminQueue.new => #<AdminQueue:0x240a910 @attributes={"topic_id"=>nil, "resolved"=>nil, "updated_on"=>nil, "action"=>nil, "type"=>nil, "post_id"=>nil,
2006 Jan 16
2
ActiveRecord: table name with spaces?
Howdy. I''m trying to work with a legacy SQL Server database where some of the table names have spaces in them. I''ve done set_table_name "tablename with spaces", but I can''t get find(:all) to work. I get the following error (because apparently it''s not putting [ ] around the name as is required for SQL Server for names with spaces.
2008 Sep 23
3
Finding distinct months using find_by_sql
Hello, I''m wondering if someone might be able to offer me a solution to the following problem that has so far stumped me. I''m trying to get the distinct months (and years) from a date field to display as a list in a view. For example, there might be a number of records stored with dates in the table ''headlines'': name date record1 21-09-2008 record2
2010 May 25
1
find_by_sql timestamp parameter
Hi In controller I have this query: @price_stat = Price.find_by_sql("select id, cost, tour_id, unix_timestamp(created_at) from prices") when I try to display result''s created_at column I don''t have any results: <% @price_stat.each do |p| %> <p><%= p.created_at %></p> <% end %> result is empty But if I try without unix_timestamp. ie:
2008 Mar 14
2
MySQL IN clause for an array of strings
I''m trying (for the first time) to build an IN clause from an array of strings and getting an error using MySQL as the DB... Here''s the code I''m using to build the clause: zips_clause = '''' user.get_zipcodes.each {|z| zips_clause += '','' if !zips_clause.blank? zips_clause += ''\'''' + z +
2008 Aug 05
2
95% CI bands on a Lowess smoother
Hi there, I'm plotting some glass RI values just by plotting plot(x) then I put on my lowess smoother lines(lowess(x)) now I want to put on some 95% Confidence Interval bands of the lowess smoother, but don't know how?? Thanks -- Gareth Campbell PhD Candidate The University of Auckland P +649 815 3670 M +6421 256 3511 E gareth.campbell@esr.cri.nz gcam032@gmail.com [[alternative