Hello, Thank you all in advance for your help with this. Environment: Windows XP Pro (Development only) Ruby 1.84 Rails 1.1.0 SaltedHashLoginGenerator Plugins: file_column, userstamp I have a user table per the salted_hash_login generator. I have an orders table that has a column named created_by that is updated by the userstamp plugin. I am trying to retrieve all of the orders for a single user (the one logged in) and am not sure how to do it. When I use this code in my order model it works: def self.my_orders find(:all, :conditions => "created_by = 1", :order => "created_on desc") end I want to create dynamic queries and need to use the created_by column to do it. I appreciate any help you all can give me. Also, in order to not ask so many newbie questions, I have purchased a few books: Agile Web Development with Rails, Rails Recipes, and the O''Reilly (beta) book Rough Cuts: Ruby on Rails - Up and Running. Can anyone point me in the direction of other good books? Thanks. Sincerely, Robert Dempsey -- Posted via http://www.ruby-forum.com/.
On Apr 3, 2006, at 22:46, Robert Dempsey wrote:> def self.my_orders > find(:all, > :conditions => "created_by = 1", > :order => "created_on desc") > end > > I want to create dynamic queries and need to use the created_by column > to do it.orders = Order.find_by_created_by(@user.id) Or even better if you set up assocations: class User < ActiveRecord::Base has_many :orders, :foreign_key => ''created_by'', :order => ''created_on desc'' end orders = @user.orders -- Jakob Skjerning - http://mentalized.net
Robert Dempsey wrote:> Can anyone point me in the > direction of other good books? Thanks.I strongly recommend Ruby for Rails by David Black ( http://manning.com/books/black ). I''ve had many "aha" moments so far and still got 6 chapters to go. It''s very well written and easy to understand. /Stefan -- Posted via http://www.ruby-forum.com/.
Stefan Liden wrote:> Robert Dempsey wrote: >> Can anyone point me in the >> direction of other good books? Thanks. > > I strongly recommend Ruby for Rails by David Black ( > http://manning.com/books/black ). I''ve had many "aha" moments so far and > still got 6 chapters to go. It''s very well written and easy to > understand. > > /StefanThank you both for your help. I will implement the given code and purchase the book right away. I hope to cut down on all of my newbie questions. Thank you again. Sincerely, Robert Dempsey -- Posted via http://www.ruby-forum.com/.
Seemingly Similar Threads
- Userstamp Plugin
- best way to add "created_by" entries to all tables???
- validates_uniqueness_of where scope euqals created_by "magic" field
- Userstamp plugin doesn't load in "test" environment - y not?
- How to write manage created_on and created_by via mixin?