Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Primary keys are not recognized in database views (mysql) #1910

Closed
iverds opened this Issue · 2 comments

3 participants

@iverds

Hi.

We have used database views to share database content between rails application, and experience problems with a many to many association. With a has_many through setup, the current query from the app using views returns:

Role.first.users :

SELECT `users`.* FROM `users` INNER JOIN `users_roles` ON `users`.`` = `users_roles`.`user_id` WHERE `users_roles`.`role_id` IS NULL

After we looked into it, it seems to us that when the database views don't have any explicit keys, it is not recognized, and it generates IS NULL instead of == 1

UPDATE:
Can be resolved by setting set_primary_key "id"

Thanks!

@chrismealy

Thanks for posting this. It solved my problem too.

@kennyj
Collaborator

I'm closing this issue, because it seems to be solved already.
If you have any problem, please comment to this issue.

BTW, I think that A View (except so-called materialized view) has no keys.

@kennyj kennyj closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.