Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error finding table #442

Closed
deanpcmad opened this issue May 14, 2015 · 8 comments
Closed

Error finding table #442

deanpcmad opened this issue May 14, 2015 · 8 comments

Comments

@deanpcmad
Copy link

Hey there. I'm currently trying to add Globalize into an open source project I am part of called Shoppe - tryshoppe/shoppe

I've added the gem, required it in shoppe.rb and the model I'm using it in (ProductCategory) and I've created the migration to create the table

class CreateShoppeProductCategoryTranslationTable < ActiveRecord::Migration
  def up
    Shoppe::ProductCategory.create_translation_table! name: :string, permalink: :string
  end
  def down
    Shoppe::ProductCategory.drop_translation_table!
  end
end

When going to view existing product categories or create new ones, I get this error:

Mysql2::Error: Unknown column 'shoppe_product_category_translations.name' in 'order clause': SELECT `shoppe_product_categories`.* FROM `shoppe_product_categories`  ORDER BY shoppe_product_category_translations.name

The shoppe_product_category_translations table does exist so I can't work out why this error is happening...

vcu9hhphz6

Any ideas?

@firedev
Copy link

firedev commented May 14, 2015

Hey what app is this?

@simi
Copy link
Member

simi commented May 14, 2015

SELECT `shoppe_product_categories`.*
FROM `shoppe_product_categories`
ORDER BY shoppe_product_category_translations.name

You're ordering by shoppe_product_category_translations table column, but that table is not used in that query resulting into "shoppe_product_category_translations.name" as unknown column for ordering.

@deanpcmad
Copy link
Author

@firedev the MySQL app? That's Querious. I only found it the other day after having issues with Sequel Pro

@deanpcmad
Copy link
Author

@simi I'm just using Shoppe::ProductCategory.new and it shows that error

@deanpcmad
Copy link
Author

Actually I think I've found the issue. There was a list of nested categories that was being ordered on that page. Will try and change that...

@firedev
Copy link

firedev commented May 14, 2015

Thanks @deanperry

@barnaclebarnes
Copy link

I'm getting a similar issue. I have this in my controller (I'm using will_paginate as well):

@museums = Museum.page(params[:page]).order(name: asc)

Name is a translated field and the tables are all set up OK (Calling a single museum works fine). This is the error I am getting:

Mysql2::Error: Unknown column 'museum_translations.name' in 'order clause': SELECT  `museums`.* FROM `museums`  ORDER BY `museum_translations`.`name` ASC LIMIT 80 OFFSET 0

I'm not sure how Globalise is meant to do ordering and how it puts together the query, Is there something I'm doing wrong/don't understand?

@barnaclebarnes
Copy link

Scrap my comment. It seems that you have to use joins(:translations) if you want to use a translated field on a where clause. This isn't really documented and is a bit confusing. I was expecting it to automagically do the join if I had a translated field in a where clause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants