ruby on rails - ActiveRecord scope does not working -
i have following relation:
class user < activerecord::base has_many :incoming_delegations, :class_name => "delegation", :foreign_key => :to_user_id, :conditions => { :active => true } #... end
and
class delegation < activerecord::base belongs_to :from_user, :class_name => "user" belongs_to :to_user, :class_name => "user" scope :from, lambda { |user| where(:from_user_id => user.id) } scope :to, lambda { |user| where(:to_user_id => user.id) } #... end
now when do
delegation.from(user.find(43)) # list of delegations user user.last.incoming_delegations # list of incoming delegations
but when try:
user.last.incoming_delegations.from(user.find(43))
then following error message:
typeerror: cannot visit user /home/jiri/.rvm/gems/ruby-1.9.3-p194@om/gems/arel-3.0.2/lib/arel/visitors/visitor.rb:25:in `rescue in visit' /home/jiri/.rvm/gems/ruby-1.9.3-p194@om/gems/arel-3.0.2/lib/arel/visitors/visitor.rb:19:in `visit' /home/jiri/.rvm/gems/ruby-1.9.3-p194@om/gems/arel-3.0.2/lib/arel/visitors/to_sql.rb:281:in `visit_arel_nodes_joinsource' /home/jiri/.rvm/gems/ruby-1.9.3-p194@om/gems/arel-3.0.2/lib/arel/visitors/visitor.rb:19:in `visit' /home/jiri/.rvm/gems/ruby-1.9.3-p194@om/gems/arel-3.0.2/lib/arel/visitors/to_sql.rb:135:in `visit_arel_nodes_selectcore' /home/jiri/.rvm/gems/ruby-1.9.3-p194@om/gems/arel-3.0.2/lib/arel/visitors/mysql.rb:41:in `visit_arel_nodes_selectcore' /home/jiri/.rvm/gems/ruby-1.9.3-p194@om/gems/arel-3.0.2/lib/arel/visitors/to_sql.rb:121:in `block in visit_arel_nodes_selectstatement' /home/jiri/.rvm/gems/ruby-1.9.3-p194@om/gems/arel-3.0.2/lib/arel/visitors/to_sql.rb:121:in `map' /home/jiri/.rvm/gems/ruby-1.9.3-p194@om/gems/arel-3.0.2/lib/arel/visitors/to_sql.rb:121:in `visit_arel_nodes_selectstatement' /home/jiri/.rvm/gems/ruby-1.9.3-p194@om/gems/arel-3.0.2/lib/arel/visitors/mysql.rb:36:in `visit_arel_nodes_selectstatement' /home/jiri/.rvm/gems/ruby-1.9.3-p194@om/gems/arel-3.0.2/lib/arel/visitors/visitor.rb:19:in `visit' /home/jiri/.rvm/gems/ruby-1.9.3-p194@om/gems/arel-3.0.2/lib/arel/visitors/visitor.rb:5:in `accept' /home/jiri/.rvm/gems/ruby-1.9.3-p194@om/gems/arel-3.0.2/lib/arel/visitors/to_sql.rb:19:in `accept' /home/jiri/.rvm/gems/ruby-1.9.3-p194@om/gems/arel-3.0.2/lib/arel/visitors/bind_visitor.rb:11:in `accept' /home/jiri/.rvm/gems/ruby-1.9.3-p194@om/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in /home/jiri/.rvm/gems/ruby-1.9.3-p194@om/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:18:i ... 1 levels...
any idea cause problem?
scope :from, lambda { |user| where(:from_user_id => user.id) }
from
bad name scope; name else.
this from
method within arel being used when you're trying call :from
scope in delegation
class.
Comments
Post a Comment