Hello everybody,
I have 2 tables users and videos. I create another table (video_users)
to link them with easiness of rails.
On the view when user 1 clic play button to view video 1, user_id and
video_id are load automatically on table videos_users.
When user clic again, the same thing append on new record.
Example:
This is what happend on database:
user_id video_id
1 1
1 1
How can I have something like this?
user_id video_id number_view
1 1 2
Model User:
class User < ActiveRecord::Base
has_many :video_users
has_many :videos, through: :video_users
end
Model Video:
class Video < ActiveRecord::Base
has_many :video_users
has_many :users, through: :video_users
end
Model VideoUser
class VideoUser < ActiveRecord::Base
belongs_to :video
belongs_to :user
end
Migration video_users:
class CreateVideoUsers < ActiveRecord::Migration
def change
create_table :video_users do |t|
t.references :video, index: true
t.references :user, index: true
t.timestamps
end
end
end
When i tried to create column number_view, i have some error:
SQLite3::SQLException: no such table: videos_users: ALTER TABLE
“videos_users” ADD “number_view” integer DEFAULT 1
Thank you very much