similar to: ActiveRecord-2.2.2, association preloading, joins and order parameter weirdness

Displaying 20 results from an estimated 6000 matches similar to: "ActiveRecord-2.2.2, association preloading, joins and order parameter weirdness"

2006 Apr 29
2
counter_caching clobbered when preloading association ?
Hi, I''m trying to use counter caching in a tree structure (in this case Bob Silva''s threaded list). This is the definition: class Folder < ActiveRecord::Base acts_as_threaded has_many :files end I would like each parent to have the total count of all the childrens member. So when inserting a new file I update the file_count following the parent_id through all the
2006 Jun 04
4
"can''t convert Magick::GravityType into Integer"
Am having trouble with file_column -- on certain crop operations, it says: A TypeError occurred in [controller]#[action]: can''t convert Magick::GravityType into Integer [RAILS_ROOT]/vendor/plugins/trunk/lib/magick_file_column.rb:90:in `crop'' Any advice? Here''s the backtrace: [RAILS_ROOT]/vendor/plugins/trunk/lib/magick_file_column.rb:90:in `crop''
2006 May 10
3
has_many association.
I''m creating a address book. A user can have many contacts. In the user model, I put: has_many :contacts And in the contact model, I put: belongs_to :user To list all contacts, I search as following: @user = User.find(session[:user_id]) And rendering: <%= render(:partial => "contact", :collection => @user.contacts)%> To persist I am using the following
2006 Mar 21
3
Newbie - ActiveRecord relationships
So I''ve worked through Agile Web Development with Rails and I''m now trying my first little app to get into the swing of things. Its a task tracking app where people can create tasks and assign them to others, and also log time against the tasks. I''m having trouble working out the model relationships. This is what I''ve got so far, but its not right as
2006 Nov 04
2
adding a method to an ActiveRecord Object
I''ve already pulled my object from the database. Now I want to add a method. What I''m doing is adding the username to the activerecord object so I''ll have the name and user_id. How can I do this. The code below fails in the view. It appears it''s overwriting the rest of my object def self.find_with_author(id) @article = Article.find(id)
2012 Jun 04
1
How to save the user_id in a separate column when using ActiveRecord::SessionStore?
Hi! I''m converting my Rails 3.1 app from cookie sessions to database sessions. I''ve added an extra column on the sessions table to save the user_id. I read the documentation in http://apidock.com/rails/v3.1.0/ActiveRecord/SessionStore and googled but can''t seem to find a way to set the session''s user_id that works. Can someone help? Thanks -- Posted via
2012 Aug 17
3
Rails doesn't validate create_model or build_model (has_one association)
I''ve got User has_one Shop. Rails is not validating when I tried create_shop or build_shop, neither in the browser nor the rails console. My code: class Shop < ActiveRecord::Base attr_protected :user_id belongs_to :user validates_presence_of :name, :primary_address, :city, :country_code, :currency end class ShopsController < ApplicationController before_filter
2011 Nov 02
2
Specify and validate requirements on an ActiveRecord association
Looking for some guidance/support on what feels like might not be an uncommon use-case. `User.has_many accounts` `User.has_many payment_methods` `Account.belongs_to :user` `Account.belongs_to :payment_method` `PaymentMethod.has_many :accounts` There are lots of `Accounts`. When I (a `User`) want to assign accounts to a `PaymentMethod`, I really don''t want to scope against all of them,
2008 Aug 26
9
stub_model() and ActiveRecord Associations
Hi all, I have what I thought was quite a simple requirement but something to do with the way ActiveRecord''s associations work is making it quite puzzling. I guess I can sum it up with this failing test: before(:each) do @source_comment = @source.comments.create(:user_id => 1) @target_comment = @target.comments.create(:user_id => 1) end
2012 Jan 18
2
Polymorphic and standard association issue
Hello all, I''m having a strange issue with a model that belongs_to two other models. The one association is polymorphic and the other is normal. ================================ class Role < ActiveRecord::Base belongs_to :user belongs_to :permission, :polymorphic => true end class User < ActiveRecord::Base has_many :roles has_many :programs, :through => :roles end
2008 Jan 30
0
Plugin belongs_to Model Association Bug
Hey all, I''m not positive if this is a Engines bug, but it seems very peculiar and a few hours of Googling haven''t given me any good leads yet, so I thought I''d see if it makes sense to any of you: I am writing a new version of the savage_beast plugin (implements Beast forums as a plugin) that''s Rails 2.0 compatible, and I am having trouble with the many
2008 Jul 07
1
Interest in a Use R Group in San Francisco area?
All, Tuesday week (July 15th) Mike Driscoll & I will be presenting "A Gentle Introduction to R and its Applications in Business Intelligence" at the SDForum Business Intelligence SIG in Palo Alto, California. One motivation is to judge interest in starting a Use R Group in the Bay Area. We will have an informal organizational meeting after the talk. We hope all local R
2007 Apr 04
1
pontential bug in rspec_on_rails and ActiveRecord transactions
Hello rspec-users, I''ve encountered a strange bug in rspec, but it may be me who is wrong. I''m running latest version from the trunk (r1678) of both rspec and rspec_on_rails. Please consider the following model: class Url < ActiveRecord::Base def after_save Contact.create!(:primary_email => ''user at example.com'') raise
2005 Aug 28
6
ActiveRecord Question
Hi all I am new to Rails, and obviously I''m missing something, I''ll get straight to the question: A User has many operations (granted to her), each Operation is associated with an OperationType. Each Operation may be associated with more then one User. So the model goes like this: class User < ActiveRecord::Base has_and_belongs_to_many :operations
2005 Jun 30
2
Find by ID plus conditions -> ActiveRecord::RecordNotFound
Hi I''m trying to understand the AR find facilities, described here: http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000650 I have a list of ids that I want to retrieve, but have a condition that should restrict the list returned: return self.find( noteids, :conditions => [ "(private = 0 OR (private = 1 AND user_id = ?))", userid] ) According to the
2006 Feb 28
6
Activerecord equivalent of the SQL "SUM()" function.
Search doesn''t seem to be working, so forgive me if I''m covering old ground here, but I''m having a difficult time figuring out how to implement a "SUM()" function using Active record. Obviously, I could just create a query, but I''d rather make it part of my active record object. Basically I have an object called "Report <
2006 Nov 04
0
test/controller not using activerecord session
I''m using zentest and the test::rails class to do my controller testing, and the following line in my controller throws an error: session.model.user_id = user.id It looks like session is just a hash when testing, which would be well and good except that now I have to write if session.respond_to?(:model) session.model.user_id = user.id end which doesn''t feel right to me
2006 Feb 18
0
activerecord connections with xmlrpc
Hi folks, Im trying to use an xmlrpc server and have it serve data using activerecord, but every request seems to eat up a mysql database connection, until I run out with "Too many connections". I don''t know enough ruby/rails (or rather ActiveRecord) to figure this one out. > ruby -v ruby 1.8.4 (2005-12-24) [i686-linux] > rails -v Rails 1.0.0 code below: Here is some
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
2006 Apr 07
2
ActiveRecord find all based on array -- need ids from array
Does anyone know if it is possible to perform an ActiveRecord find by passing in an array? I would like to be able to do the following: MyModel.find(:all, :conditions => ["user_id in (?)", users]) The problem I run into is that the returned SQL contains the to_s() output of the User object, not the ids of those users. Is it possible to change this behavior? I attempted to