Reply to topic
joining on the paginator
Xtatic


Joined: 28 Aug 2006
Posts: 3
Reply with quote
Hi!

I can't seem to guess how I should specify the join between these two tables, to have the category name added to the output.
The tables are
Code:
   
    create_table "message_categories", :force => true do |t|
      t.column "name", :string, :null => false
    end
   
    create_table "messages", :force => true do |t|
      t.column "message_category_id", :integer, :default => 0, :null => false
      t.column "name", :string, :null => false
      t.column "sort", :integer, :null => false     
    end


the code I tried to add is
Code:

def component 
    @show_wrapper = true if @show_wrapper.nil?
    @sort_sql = Message.scaffold_columns_hash[current_sort(params)].sort_sql rescue nil
    @sort_by = @sort_sql.nil? ? "#{Message.table_name}.#{Message.primary_key} asc" : @sort_sql  + " " + current_sort_direction(params)
    @paginator, @messages = paginate :messages, :per_page => 40, :order => 'sort DESC, name', :joins => "#{MessageCategory.name}"
   
    render :action => "component", :layout => false
  end


In particular, I added :joins => "#{MessageCategory.name}", but I cannot find any example and I'm definitely doubtful about the syntax. Last but not least, I'm using ajax_scaffold, which is one of the greatest things I ever saw (and in 28 years of work I saw a lot of them). Very Happy

Any hint is extremely welcome.
Xtatic


Joined: 28 Aug 2006
Posts: 3
Reply with quote
okay I found a first answer, at least formally all I need is plain SQL

Code:
@paginator, @messages = paginate :messages, :per_page => 30, :conditions => "m.message_category_id=mc.id", :joins => "m, message_categories mc", :select => "m.*, mc.name AS category_name", :order => 'mc.name, m.sort, m.name'


Too bad I don't see the category name in the view Evil or Very Mad So acting on the paginator was NOT the answer, after all... any hint?
Xtatic


Joined: 28 Aug 2006
Posts: 3
Reply with quote
LOL it was born as a question, it evolved into a blog Very Happy

The answer for all such questions is here http://height1percent.com/articles/2006/04/18/ajaxscaffold-3-1-0-released

The more I see Ruby, the more I love it... I just wish it had a central doc repository in the friendly, commented PHP style. It would save us all a lot of trouble.
joining on the paginator
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic