473,396 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to delete data in in project table and task table with just a relational id?

Exequiel
288 256MB
Hi I have 2 tables in database, and i want to know how i can delete the data in tasks table after i delete the data in projects table, the task table is connected by a project_id in projects table's id,

heres the tables. . .

Expand|Select|Wrap|Line Numbers
  1.  Table for projects"
  2.    Column   |            Type             |                       Modifiers                       
  3. ------------+-----------------------------+-------------------------------------------------------
  4. id         | integer                     | not null default nextval('projects_id_seq'::regclass)
  5. title      | character varying(255)      | 
  6. description | character varying(255)      | 
  7. user_id    | integer                     | 
  8. created_at | timestamp without time zone | not null
  9. updated_at | timestamp without time zone | not null
  10. addbyemail | character varying(255)      |  
  11.  
  12.                                        Table for tasks"
  13.      Column      |            Type             |                     Modifiers                      
  14. ------------------+-----------------------------+----------------------------------------------------
  15. id               | integer                     | not null default nextval('tasks_id_seq'::regclass)
  16. todo             | character varying(255)      | 
  17. project_id       | integer                     | 
  18. assigned_user_id | integer                     | 
  19. created_at       | timestamp without time zone | not null
  20. updated_at       | timestamp without time zone | not null
  21.  
  22.  
i want to delete the data using rails.

heres my code in db/migrate for projects table
Expand|Select|Wrap|Line Numbers
  1. class CreateProjects < ActiveRecord::Migration
  2.   def change
  3.     create_table :projects do |t|
  4.       t.string :title
  5.       t.string :decription
  6.       t.integer :user_id
  7.  
  8.       t.timestamps
  9.     end
  10.   end
  11. end
  12.  
migration for tasks table
Expand|Select|Wrap|Line Numbers
  1. class CreateTasks < ActiveRecord::Migration
  2.   def change
  3.     create_table :tasks do |t|
  4.       t.string :todo
  5.       t.integer :project_id
  6.       t.integer :assigned_user_id
  7.  
  8.       t.timestamps
  9.     end
  10.   end
  11. end
  12.  
heres my code in my app/controllers/projects_controller.erb
Expand|Select|Wrap|Line Numbers
  1. def destroy
  2.     @project = Project.find(params[:id])
  3.     @project.destroy
  4.  
  5.     respond_to do |format|
  6.       format.html { render action: 'show' }
  7.       format.json { render :json => { :status => 'Ok', :message => 'Project was successfully Deleted'} }
  8.     end
  9.   end
  10.  
Please help me. any body please? tank you so much...
Jun 26 '14 #1
0 6014

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Matt | last post by:
Hi all, We recently upsized two Microsoft Access Databases to SQL. We're using an ADP (2002) as the front end. All the conversion issues have been resolved, except for one: Whenever we...
1
by: John Baker | last post by:
Hi: I am working with an XLS file, andhave Access 2000. When I try and clear the xlf file (so that xls can use it for additional data), I get an error message: "Deleting data in a linked...
1
by: VMI | last post by:
How can I dump a datatable into an Access table (which contais exactly the same structure)? Somebody suggested doing this with a dataAdapter. I don't want to run an Insert query for each record (I...
1
by: joe | last post by:
I'm probably just missing something, but I've been trying to work through some examples, and have wound up with a couple messed up project I'd like to get rid of. So far, the help has been no help,...
4
by: Akinyemi | last post by:
I am currently using Visual Basic 6 to write a Payroll Program. I created a Database with one Table in Microsoft Access that ships with Office 2000. The name of the Database is "Payroll", and the...
11
by: LiDongning | last post by:
I have a situation here: every month there will be a table (with 3200+- entries) that should be appended to a Year-to-Date table. I appended the second month's live table to the accumulative...
4
by: Alexis | last post by:
Hello, I'm facing oracle trigger problem. Anyone can help or advise how to resolve it? Below are the explaination on my problem I've created a trigger for my program. When there is a new...
3
by: blakerrr | last post by:
Hi All, I have a strange situation that I can't figure out. The task is quite simple, delete a record from a table. Here is my situation: I have a form called Order Create which cycles through...
5
by: dos360 | last post by:
Hello, I have two tables, one is a list of activities, the other a list of participants. I want to insert one record in the activities table and then using its identity column as foreign key, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.