Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7600911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:02:01+00:00 2026-05-30T23:02:01+00:00

I have two models: TimeLog and Task . TimeLog belongs to Task and Task

  • 0

I have two models: TimeLog and Task. TimeLog belongs to Task and Task has many TimeLogs.

In the past some Tasks were deleted but the corresponding TimeLogs were not deleted (the cascade delete wasn’t working). So we have some broken TimeLogs. They do have a task_id but that task_id does not exist anymore.

I have two questions:

1) I want to get all the TimeLogs from a user but filtering the broken ones.

i.e

TimeLog.find(:all, :conditions => ['time_log.user_id = ? and <time_log.task_id exists>])

2) I want to get all the broken TimeLogs in the console to delete them manually.

i.e.

TimeLog.find(:all, :conditions => [<!time_log.task_id exists>])

How can I do that?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:02:03+00:00Added an answer on May 30, 2026 at 11:02 pm

    Add something like the following where() to your chain of ActiveRelation calls to include any orphaned TimeLogs:

    .where('NOT EXISTS SELECT * FROM tasks where tasks.id = timelogs.task_id')
    

    …and obviously if you remove the NOT you’ll explicitly exclude any orphaned records.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models Project and 'Task` where project has_many tasks and task belongs
I have two models in Django: groups and entries. Groups has a many-to-many field
I have two models, one is Group, the other Item. A group has many
I have two models: Show and Venue . Show has one venue while each
I have two models Customer and Referal. Both have an email attribute. Referal belongs
I have two Models, one that has the name Exam and one that has
I have two models e.g. Book and Author . An author can have many
I have two models that has a manytomany relationship with a 'through' table in
I have two models: releases have many elements, and elements belong to releases. The
I have two models in relation one-to-many: class Question(db.Model): questionText = db.StringProperty(multiline=False) class Answer(db.Model):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.