custom sql database queries inside controller

14 views
Skip to first unread message

hobo_hippy

unread,
Oct 19, 2011, 10:33:32 PM10/19/11
to Hobo Users
I'm finding myself stuggling more and more often trying to figure out
how to develop custom database queries from within a controller. I've
found lots of resources, one of which being
http://guides.rubyonrails.org/active_record_querying.html but nothing
i've found is hobo specific. Is there a hobo way to do this sort of
thing? I feel like what I've been dealing with is a hodgepodge of
techniques.

In short, is there a clear reference anywhere on all available
activerecord queries I can use in a hobo controller?


This is about the limit to what I can do.

@myOrder = Order.find :first, :limit => 1, :conditions => {:user_id =>
current_user}

As far as I understand, what the above line does is as follows:

find, among the models called orders, any models where the userId is
the same as the current user (condition), starting with the first one
found(:first), and only return 1 instance(:limit => 1).

If anyone has a good reference as to all the commands I can use in a
query like this, I would be much appreciative. If not, I'd like to
start a conversation to confer about the different kinds of things you
can and can't do with activerecord queries like above.


-HoboHippy

hobo_hippy

unread,
Oct 19, 2011, 11:00:51 PM10/19/11
to Hobo Users
I have another resource:
http://api.rubyonrails.org/classes/ActiveRecord/Base.html

this seems quite useful, however I attempted the following instead of
the example I have listed in my previous post:

@myOrder2 = Order.where(:user_id => current_user)

but I just get:

undefined method `where' for #<Class:bunch of numbers

I'm running rails 2.3.5 and hobo 1.0.3. Is the failure due to my
version? Do I need rails 3.0+ and a newer version of hobo? what
methods can I use with rails 2.3.5 and hobo 1.0.3 other than
object.find?

-hobo_hippy


On Oct 19, 10:33 pm, hobo_hippy <87bee...@gmail.com> wrote:
> I'm finding myself stuggling more and more often trying to figure out
> how to develop custom database queries from within a controller. I've
> found lots of resources, one of which beinghttp://guides.rubyonrails.org/active_record_querying.htmlbut nothing

kevinpfromnm

unread,
Oct 20, 2011, 12:15:42 PM10/20/11
to hobo...@googlegroups.com
the .where (and other associated methods) are part of rails 3.  If you're just starting learning, it might be best to move up to rails 3 and hobo 1.3 as that's going to be the approach going forward.

Your prev post, the limit option is redundant as :first only grabs one item.

hobo_hippy

unread,
Oct 23, 2011, 3:19:52 AM10/23/11
to Hobo Users
thanks. I've just upgraded to rails 3 and hobo 1.3. I'm creating a new
post with questions about 1.3 :3
Reply all
Reply to author
Forward
0 new messages