search for: count_by_sql

Displaying 20 results from an estimated 39 matches for "count_by_sql".

2006 Jan 19
7
bug in has_many count?
...9;'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) if @reflection.options[:counter_sql] @reflection.klass.count_by_sql(@counter_sql) elsif @reflection.options[:finder_sql] @reflection.klass.count_by_sql(@finder_sq...
2006 Jul 27
5
Calculate methods on attr_accessor objects
Is it possible to use the calculate methods (sum, etc.) on attr_accessor attributes? Ie: Class Item < ActiveRecord::Base attr_accessor :total_cost def total_cost @total_cost = self.cost_unit * self.amount end calling Item.sum(:total_cost) or Item.sum(''total_cost'') both return a unknown column ''total_cost'' mysql error. I thought that active
2006 Aug 13
3
ruby and mysql syntax? tried single quotes, double, none, ...
Hi, how do i use passed in arguments and convert those to something sql can understand? do the aliases have to be double qouted? single qouted? i think i tried all but no avail...thanks! def get_count(doctype, towne) @profiles = Profile.count_by_sql("SELECT COUNT(*) from Profiles where Profiles.doctype_id = 1 and town_id = towne") end -- Posted via http://www.ruby-forum.com/.
2006 Apr 06
6
pagination question
i''ve figured out how to use the next and previous links with the paginator class but now i''m trying to figure out how to display all the page numbers in between. looking through the rails api, i found paginator.each() but i''m not sure how to use it, or if that''s even what i am looking for. also, is there a way to limit the amount of pages like some sites
2006 Feb 09
2
postgres connection problems
.../connection_specification.rb:106:in `retrieve_connection'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:20:in `connection'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:518:in `count_by_sql'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:511:in `count'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:167:in `count_collection_for_pagination'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_co...
2006 Feb 25
5
MySQL client ran out of memory
...on_adapters/mysql_adapter.rb:175:in `select_one'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/database_statements.rb:16:in `select_value'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:518:in `count_by_sql'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:511:in `count'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/associations/has_many_association.rb:49:in `count'' Anyone have any suggestions as to what the issue mi...
2006 Feb 18
1
sql logic is killing me
...:order_by => ''facilities.name, clients.last_name, :per_page => 14) @facility = Facility.find(:first, :conditions => ["id = ?", params[:facility_id] ]) @beds_total = @facility.beds_m + @facility.beds_f + @facility.beds_a @beds_m_cnt = Client.count_by_sql("select count(*) " + " from clients where sex = ''M'' ") end the @beds_m_cnt gives me count of all Male clients but I only need the ones in @placements which I can''t seem to use in the @beds_m_cnt assignment. Is this an issue of iteration that I...
2009 Apr 11
6
Inserting data from 1 table to another by using find_by_sql
Hi All, I am inserting data from one table to another by using following method @data=RoyaltyReportFiles.find_by_sql("insert into royalty_reports (artist_name, album_name) select artist_name, album_name from temp_royalty_reports where id=328417") it saves the data into royalty_reports table but it gives following error and application crashes. i am using rails 1.2.5 You have a nil
2006 Jan 15
0
OS X Rails - Nuby
.../connection_adapters/mysql_adapter.rb:175:in `select_one'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/database_statements.rb:16:in `select_value'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:518:in `count_by_sql'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:511:in `count'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:167:in `count_collection_for_pagination'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_...
2006 Jan 07
8
Using find_by_sql to get the sum of a column
Hello, I was wondering if there was a method in Rails that returns the sum of a column. For example, I have a column called ''score'' and writing a SQL statement such a ''select sum(score) from table_name'' does return the sum of the values in the column. In the past (not too long ago being a newbie), I defined all sorts of methods only to discover that Rails
2006 May 06
7
New Ajax and Rails tutorial
Hi, I just published the first version of a small tutorial I''ve written on Ajax and Rails. It is called "How to paginate, sort and search a table with Ajax and Rails" (sorry, I didn''t manage to find a longer title !) and is available at : http://dev.nozav.org/rails_ajax_table.html There is nothing really new in it, it''s rather a compilation and
2006 Jul 16
3
pagination over custom-sorted collections?
I have a little web app where we need to paginate collections of items. I''m trying to sort the collection and then pass it, sorted, to a Paginator, and still be able to paginate through the collection, across several pages, with the new sort order. The only thing I''m doing differently from the regular scaffolding approach is this: @order_pages = Paginator.new(self,
2006 Jan 15
2
Please help - Rails hanging on mysql connection
...ord/connection_adapters/mysql_adapter.rb:175:in `select_one'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/database_statements.rb:16:in `select_value'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:518:in `count_by_sql'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:511:in `count'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:167:in `count_collection_for_pagination'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_co...
2006 May 18
8
Concatenated key
Hi all, I started playing a couple days ago with Rails and it find it very interesting. But I''m a bit stuck with making it work with a concatenated primary key. I want to use my own names for the DB fields and I''m using SQL Server 2005. My tables look roughly like this: CREATE TABLE USERS ( USR_ID VARCHAR(25) NOT NULL PRIMARY KEY, USR_PASS VARCHAR(25) ) CREATE TABLE
2006 Jun 15
1
Paginating a .find
how exactly would I apply paginate to a .find I have: @posts = Post.find(:all, :conditions => [ ''(title) OR (body) LIKE ?'', ''%'' + params[:query] + ''%''], :order => ''end_date'') How would I go about paginating the uoputed list? Something like 10 on a page. -- Posted via
2006 Apr 20
1
Returning Count from find_by_sql
I want to return an int from a find_by_sql call. But when I use that result to compare to another count the error tells me I have an array. MODEL: # Returns the number of comments in a specified post def self.find_count(post_id) find_by_sql(["SELECT COUNT(*) FROM commments WHERE post_id = ?", post_id]) end CONTROLLER: def test @post =
2006 Feb 13
0
count_as_taggable distinctly
...}.#{t_pk} AND (#{t}.name = ''#{tag_names.join("'' OR #{t}.name=''")}'') AND #{o}.#{o_pk} = #{jt}.#{o_fk}" sql << " AND #{sanitize_sql(options[:conditions])}" if options[:conditions] count_by_sql(sql) end</pre> -- Posted via http://www.ruby-forum.com/.
2006 Feb 15
0
MySql adapter error
...nnection_adapters/mysql_adapter.rb:175:in `select_one'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/database_statements.rb:16:in `select_value'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:518:in `count_by_sql'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:511:in `count'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/pagination.rb:167:in `count_collection_for_pagination'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/pagi...
2006 Feb 21
0
Rails edge breaks my app
...nnection_adapters/mysql_adapter.rb:175:in `select_one'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/database_statements.rb:16:in `select_value'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:518:in `count_by_sql'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:511:in `count'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/pagination.rb:167:in `count_collection_for_pagination'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/pagi...
2006 Feb 24
1
Returning a "select count()" in ActiveRecord
I am trying to find the count of rows on a table. If I do a result= Table.find_by_sql ("select count(distinct id) ...... It returns an array of Table with Hashes of "select count(distinct id)" making accessing it a pain result[0][''select count(distinct id)''] It seems easier to return all the rows and do a .length on the result Array.