Project

General

Profile

Actions

Defect #16397

closed

Simple Principal.joins(:projects) or Principal.joins(:memberships) throws sql error (mysql 2)

Added by Alexey Glukhov over 11 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Database
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Cant reproduce
Affected version:

Description

Hello, I am running Redmine 2.3.4 on Rails 3.2.13

Redmine has following relation in the Principal model:

has_many :projects, :through => :memberships

When running this simple activerecord query in rails:

Principal.joins(:projects)

or

Principal.joins(:memberships)

throws following error:
ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'projects.status' in 'on clause': SELECT `users`.* FROM `users` INNER JOIN `members` ON `members`.`user_id` = `users`.`id` AND projects.status<>9 INNER JOIN `projects` ON `projects`.`id` = `members`.`project_id` WHERE `users`.`type` IN ('User', 'AnonymousUser')

It's the same thing with User and Group tables. Also tried that on redmine 2.5 - still the same error.

Seems to me error is caused by principal.rb:28 line:
has_many :memberships, :class_name => 'Member', :foreign_key => 'user_id', :include => [ :project, :roles ], :conditions => "#{Project.table_name}.status<>#{Project::STATUS_ARCHIVED}", :order => "#{Project.table_name}.name"

Actions #1

Updated by Go MAEDA over 6 years ago

  • Status changed from New to Closed
  • Resolution set to Cant reproduce

Both Principal.joins(:projects) and Principal.joins(:memberships) works without errors in Redmine 4.0. Maybe the issue was fixed in some version.

Actions

Also available in: Atom PDF