Wednesday, January 5, 2011

[Rails] Re: undefined method `model_name' for ActiveRecord::Relation:Class

Thanks for looking at my problem. I hope this is what you need.

I am using a named_scope (or just scope - rails 3):

scope :students_enrolled_in_course, lambda { |*args| {
:conditions => ["crs_key > ? AND
final_gr IS NOT NULL AND
(crs_id in (?,?) AND
crs_coll in ('HA','HO') AND
substr(crs_id,3) in
(SELECT crs_link FROM sso.courses WHERE
crs_no in (?, ?)))",
args[2], 'HA'+args[1].to_s,
'HA'+args[0].to_s, 'HA'+args[0].to_s, 'HA'+args[1].to_s ],
:order => "crs_key"
}}


The resulting sql this results in is thus:
SELECT "SSO"."STCD2_COURSES".* FROM "SSO"."STCD2_COURSES" WHERE (crs_key
> 200620 AND
final_gr IS NOT NULL AND
(crs_id in ('HA211','HA2211') AND
crs_coll in ('HA','HO') AND
substr(crs_id,3) in
(SELECT crs_link FROM sso.courses WHERE crs_no in
('HA2211','HA211'))))
ORDER BY crs_key

I've run this in our Oracle DB and I get 500+ records.

Thanks.

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate