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

MyTaskboardController support for PostgreSQL #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aVolpe
Copy link

@aVolpe aVolpe commented Apr 29, 2014

If the database is MySql the column issue_statuses#is_closed is a
integer 0 or 1, but if the database is PostgreSQL, the column is
boolean.

A check for the database type is necesary to create the correct SQL to
get the task of the current user.

If the database is MySql the column issue_statuses#is_closed is a
integer 0 or 1, but if the database is PostgreSQL, the column is
boolean.

A check for the database type is necesary to create the correct SQL to
get the task of the current user.
@aVolpe
Copy link
Author

aVolpe commented Apr 29, 2014

The controller my_task_controller work only for MySQL, because this:

.where("assigned_to_id = ? AND issue_statuses.is_closed = 0 AND projects.status = 1", @user.id) \

The issue_statuses.is_closed is a int in MySQL and a boolean in PostgreSQL.

With this change it works:

if ActiveRecord::Base.connection.adapter_name == 'MySQL'
    where = "assigned_to_id = ? AND issue_statuses.is_closed == 0 AND projects.status = 1"
else
    where = "assigned_to_id = ? AND not issue_statuses.is_closed AND projects.status = 1"
end

...

   .where(where, @user.id)

@sbonnegent
Copy link

Thanks for this, I had this problem too.

@AndreMiras
Copy link

Is this not the ORM job? I don't know much about RoR, but in the pony world (Django), this is how it works. You use the ORM which takes care of the conversion itself.
Here's my take on it:

.where("assigned_to_id" => @user.id, "issue_statuses.is_closed" => false, "projects.status" => 1)

I hope ActiveRecord can convert it to appropriated database backend.

I've created a pull request #39 that implements it in an agnostic way.

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

Successfully merging this pull request may close these issues.

3 participants