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

Closed
iverds opened this Issue Jun 29, 2011 · 2 comments

Comments

Projects
None yet
3 participants

iverds commented Jun 29, 2011

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!

Thanks for posting this. It solved my problem too.

Contributor

kennyj commented Jan 31, 2012

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 Jan 31, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment