Displaying 9 results from an estimated 9 matches for "extract_options_from_args".
2006 Feb 10
1
Auto-generated find queries adding bogus WHERE clauses
[Sorry for the poor subject; this is really hard to explain]
I''m trying to run a search over several objects which themselves contain
multiple model objects, like so:
class Collection << ActiveRecord::Base
def findpkg
self.repositories.each do |r|
p = r.packages.find(:all, :conditions => "name like ''%pkg%''")
end
end
end
2006 Aug 09
7
changing find method
Hi,
i was wondering if there was a nice clean way(after all, it is ruby) to
change the find method of a certain model/class (Page) so that if i
wanted to use a find method on a @page instance it would return only
specific rows from the table(if the page.published == true/false:
the pages table looked like
SQL:
...
id int not null auto_increment,
published tinyint(1) not null,
something
2006 Jan 10
0
Day.find_all_with_appointments - INNER JOIN
...:
class Day < Foo
def self.find_all_with_appointments (*args)
find :all,
{ :select => ''distinct foos.*'',
:joins => ''INNER JOIN appointments ON days.appointment_id
= foos.id''
}.merge (extract_options_from_args!(args))
end
has_many :results , :class_name => "Result", :foreign_key
=> "event_id"
end
:include doesn''t help here, as it produces an outer join.
Alain
2005 Dec 26
0
Extend the find-method: more conditions
Hi,
I want to share some helpful code snippet. Can it further be optimized?
Or is this even good to do?
Put this in your model to write a customized find method having more
conditions:
def self.find_active(*args)
options = extract_options_from_args!(args)
conditions = "AND (#{sanitize_sql(options[:conditions])})" if
options[:conditions]
options[:conditions] = "ADDITIONAL_CONDITIONS_GO_HERE #{conditions}"
args << options
find(*args)
end
regards,
Helmut
2006 Aug 07
0
Overloading ''find''
How would I overload find?
I got some excellent help on mixins for my classes using lib/, but it
doesn''t allow find to be overloaded. I''m testing with the example method
below:
module myModule
def find(*args)
options = extract_options_from_args!(args)
validate_find_options(options)
set_readonly_option!(options)
case args.first
when :first then find_initial(options)
when :all then find_every(options)
else find_from_ids(args, options)
end
find_initi...
2005 Dec 11
4
Problem with acts_as_paranoid: "ArgumentError: Unknown key(s): group"
...activesupport-1.2.4/lib/active_support/core_ext/hash/keys.rb:48:in
`assert_valid_keys''
/usr/lib/ruby/gems/1.8/gems/acts_as_paranoid-0.2/lib/acts_as_paranoid.rb:125:in
`validate_find_options''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/base.rb:1164:in
`extract_options_from_args!''
/usr/lib/ruby/gems/1.8/gems/acts_as_paranoid-0.2/lib/acts_as_paranoid.rb:62:in
`find''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.1/lib/active_record/associations/has_many_association.rb:111:in
`find_target''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.1/...
2006 Jul 05
2
Serialized object behaves weird
Hi!
I got a class named EinsatzFilter which I serialized to session. Before
saving to session it works afterwards I keep getting the message:
"undefined method `to_s'' for #<Person:0x38c6ab8>". "Person" is a from
ActiveRecord::Base inherited class.
Code:
class EinsatzFilter
include ApplicationHelper
attr_reader :personen, :monat, :projekte, :kunde
2006 Feb 25
0
neverending i2/lighttpd problems
....5/lib/active_support/core
_ext/hash/keys.rb:48:in `assert_valid_keys''
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.
rb:1169:in `validate_find_options''
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.
rb:1164:in `extract_options_from_args!''
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.
rb:379:in `find''
/app/controllers/books_controller.rb:7:in `premiere''
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/bas
e.rb:853:in `perform_action_with...
2006 Jan 27
4
acts_as_whatever
...love the acts_as_* family that rails uses. I''ve also found I can
create something similar by dropping the following code into my
activerecord classes:
class MyClass < ActiveRecord::Base
class << self
alias_method :count_with_unapproved, :count
end
def self.find(*args)
options = extract_options_from_args!(args)
if options[:conditions].nil?
options[:conditions] = ["status = ''approved''"]
end
args << options
super(*args)
end
def self.count(conditions = nil, joins = nil)
logger.info conditions.inspect
if conditions.nil?
conditions = "status = ''approved...