Help with a bit of logic

I have two tables: ‘owner_changes’, ‘tasks’

‘tasks’ has a primary key of ‘id’. ‘owner_changes’ uses a ‘task_id’
foreign key to relate the tables. ‘owner_changes’ contains records for
every instance of a task owner change. ‘owner_changes’ also houses a
‘comment’ column to store any comments one task owner may wish to leave
the next.

I have a mailer model set up that delivers an email to the current task
owner. So far, I’ve been very pleased with this set up; it’s simply
worked without fail and my code is tight. The mailing process is
controlled by a ‘before_update’ method atop the mailer model. Here lies
the issue: a task can have multiple owner changes, an owner change can
only belong to one task. Thus, a task can have multiple comments.
Obviously, the most current owner is only concerned about the comment
that was sent to him/her. I used a simple array method (.last) to bring
the last comment from the ‘owner_change’ array. This doesn’t display the
latest comment. I understand that problem, but I’m not sure what the
best way to approach this would be.

If I’ve not been clear enough in my description, which is likely, please
specify what you’d like me to elaborate on.

Pale H. wrote:

I have two tables: ‘owner_changes’, ‘tasks’

‘tasks’ has a primary key of ‘id’. ‘owner_changes’ uses a ‘task_id’
foreign key to relate the tables. ‘owner_changes’ contains records for
every instance of a task owner change. ‘owner_changes’ also houses a
‘comment’ column to store any comments one task owner may wish to leave
the next.

I have a mailer model set up that delivers an email to the current task
owner. So far, I’ve been very pleased with this set up; it’s simply
worked without fail and my code is tight. The mailing process is
controlled by a ‘before_update’ method atop the mailer model. Here lies
the issue: a task can have multiple owner changes, an owner change can
only belong to one task. Thus, a task can have multiple comments.
Obviously, the most current owner is only concerned about the comment
that was sent to him/her. I used a simple array method (.last) to bring
the last comment from the ‘owner_change’ array. This doesn’t display the
latest comment. I understand that problem, but I’m not sure what the
best way to approach this would be.

Use :order to put the records into the order you want. Unless you do
that, the DB will return records in an unpredictable sequence.

If I’ve not been clear enough in my description, which is likely, please
specify what you’d like me to elaborate on.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Marnen Laibow-Koser wrote:

Use :order to put the records into the order you want. Unless you do
that, the DB will return records in an unpredictable sequence.

If I’ve not been clear enough in my description, which is likely, please
specify what you’d like me to elaborate on.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Thanks for your response but that, I feel, is not the issue. The
owner_change.comment is clearly being called prior to the task record
being updated, which means that the latest comment doesn’t exist at the
point of the mail being sent out.

I understand, it seems like a simple case of making this call after the
task record update, but I have other dependencies on this occurring
before the task record update.

Pale H. wrote:

Marnen Laibow-Koser wrote:

Use :order to put the records into the order you want. Unless you do
that, the DB will return records in an unpredictable sequence.

If I’ve not been clear enough in my description, which is likely, please
specify what you’d like me to elaborate on.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Thanks for your response but that, I feel,

Programming has nothing to do with what you feel.

is not the issue. The
owner_change.comment is clearly being called prior to the task record
being updated, which means that the latest comment doesn’t exist at the
point of the mail being sent out.

Then reorder the calls.

I understand, it seems like a simple case of making this call after the
task record update, but I have other dependencies on this occurring
before the task record update.

Then reorder those calls.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs