i got error following when i try to delete record from services table. i
am display data from tables services and users so that it make
"services_users"
logical table so that how to possible delete record from that table.
ActiveRecord::StatementInvalid in ServicesController#destroy
Mysql::Error: Table 'notice_development.services_users' doesn't exist:
SHOW FIELDS FROM `services_users`
RAILS_ROOT: C:/ruby/addon/notice
Application Trace | Framework Trace | Full Trace
Hi
If what I understood from your description right, you have to check
:dependent => :destroy
Assuming your relationship is has_many :through you can do like in
model
Service like
has_many :services_users, :dependent => :destroy
has_many :users, :through => :services_users
similary in model User
Then for example when you delete a service all its corresponding entres
from junction table services_users will be deleted and viceversa Please
check here
Do you have a ServicesUser join model between services and users ?
From your first post it looks like you certainly don't have a
services_users table. If you are only trying to delete a row from the
services table, what is wrong with Service.find(some_id).destroy ?
uninitialized constant Service::ServicesUser
i got this error as per your suggestion
i want to delete only from services table record not in users
Do you have a ServicesUser join model between services and users ?
From your first post it looks like you certainly don't have a
services_users table. If you are only trying to delete a row from the
services table, what is wrong with Service.find(some_id).destroy ?
Fred
i have no services_users table and ServicesUser model in my
service.rb
has_many :services_users, :dependent => :destroy
has_many :users, :through => :services_users
user.rb
has_many :services_users, :dependent => :destroy
has_many :services, :through => :services_users
services_controller.rb
@services = Service.find(:all, :select =>
'services.id,services.title,services.no_or,services.price,users.FirstName,services.created_at',:joins=>
'left join users on services.user_id = users.id')
i am using this code and access data from both table but when i try to
delete record from service i got error serviceuser