Forum: Ruby on Rails [ActiveRecord] How to avoid touching a class more than once in a reference hierarchy

Posted by Snow Hellsing (Guest)
on 2013-01-10 14:26
(Received via mailing list)
say there are AR classes (omitted ` < ActiveRecord::Base`):
```ruby
class Project
end

class Member
  belongs_to :project, touch:true
end

class Todolist
  belongs_to :project, touch: true
end

class Todo
  belongs_to :todolist, touch: true
  belongs_to :member, touch: true
end
```

When I save a Todo instance, referenced Project instance will be touched
twice.
Is there any way to avoid this?

Appreciate for help. And sorry if my English is broken.
Posted by Colin Law (Guest)
on 2013-01-10 14:31
(Received via mailing list)
On 10 January 2013 08:03, Snow Hellsing <snow.hellsing@gmail.com> wrote:
>   belongs_to :project, touch: true
> Is there any way to avoid this?
First a question, will the todolist and member that a todo belongs to
always belong to the same project?  So rather than being one project
touched twice it may be two separate projects?

Colin
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.