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

User id is 0 by default #1

Open
cupakromer opened this issue Aug 27, 2015 · 0 comments
Open

User id is 0 by default #1

cupakromer opened this issue Aug 27, 2015 · 0 comments

Comments

@cupakromer
Copy link

Related to this Stackoverflow comment.

From what I can see you've setup your system to generate 0 ids.

Your schema is stating that you do not want Rails to tell the database to set the id field as auto incrementing. You also are telling Rails to tell the database to set the id value to be 0 by default if one is not provided.

create_table "users_view", id: false, force: :cascade do |t|
  t.integer  "id",         limit: 4, default: 0, null: false

In your model you tell Rails to use the id as the primary key and to use a custom table. Based on your schema it's an actual table, not a view.

self.table_name = "users_view"
self.primary_key = "id"

Based on all that I would expect the following to be true:

u = User.create!
u.id
# => 0
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

1 participant