# Having a problem initializing an associated table

**URL:** <https://www.ruby-forum.com/t/having-a-problem-initializing-an-associated-table/202857>\
**Category:** Rails\
**Created:** [February 7, 2011, 10:06pm UTC](https://www.ruby-forum.com/t/having-a-problem-initializing-an-associated-table/202857 "2011-02-07T22:06:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [February 7, 2011, 10:06pm UTC](https://www.ruby-forum.com/t/having-a-problem-initializing-an-associated-table/202857/1 "2011-02-07T22:06:36Z")

</div>

Q. What am I doing wrong such that tx\_batch\_mtime is not receiving the  
value I believe that I am assigning? At this point current\_entry has  
not itself been saved.

I have this code:

puts( “\*\*\* \*\*\*” \*3 )

```
  current_log_entry = current_entry.edi_log_entries.build

```

puts( current\_log\_entry.class )  
puts( hash[:current\_batch][:tx\_batch\_mtime] )

```
  current_log_entry.tx_batch_mtime = \ # linebreak for clarity
    hash[:current_batch][:tx_batch_mtime]

```

puts( current\_log\_entry.to\_yaml )  
puts( current\_entry.cctn )  
puts()

Which produces this output:

```
  *********  *********
  CaCustomsEdiLogEntry
  1276181402
  --- !ruby/object:CaCustomsEdiLogEntry
  attributes:
    tx_batch_number:
    created_at:
    changed_by: " "
    tx_message_function:
    tx_record_type:
    tx_batch_date:
    lock_version: 0
    tx_batch_account:
    created_by: " "
    accessed_at:
    tx_batch_mtime:
    tx_message_data:
    changed_at:
    accessed_from: " "
    ca_customs_entry_id:
    accessed_by: " "
  attributes_cache: {}

  changed_attributes: {}

  destroyed: false
  marked_for_destruction: false
  persisted: false
  previously_changed: {}

  readonly: false
  13466600016294

  1276181402
  20100610
  13466
  009

```

As you can see, current\_edi\_log.tx\_batch\_mtime is nil whereas I expect  
it to be 1276181402. Why?

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [February 7, 2011, 10:18pm UTC](https://www.ruby-forum.com/t/having-a-problem-initializing-an-associated-table/202857/2 "2011-02-07T22:18:55Z")

</div>

On 7 February 2011 21:06, James B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> puts( current\_log\_entry.class )  
> puts( hash[:current\_batch][:tx\_batch\_mtime] )
> 
> current\_log\_entry.tx\_batch\_mtime = \ # linebreak for clarity

The \ must be the last char on the line, though I would have expected  
this to generate a compile error.

If still not working use ruby-debug to break into the code and inspect  
data to see what is going on. See Rails Guide on debugging if unsure  
how to do this. I is often a lot easier than loads of debug o/p.

Colin

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [February 7, 2011, 10:47pm UTC](https://www.ruby-forum.com/t/having-a-problem-initializing-an-associated-table/202857/3 "2011-02-07T22:47:39Z")

</div>

Colin L. wrote in post #980132:

> On 7 February 2011 21:06, James B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > puts( current\_log\_entry.class )  
> > puts( hash[:current\_batch][:tx\_batch\_mtime] )
> > 
> > current\_log\_entry.tx\_batch\_mtime = \ # linebreak for clarity
> 
> The \ must be the last char on the line, though I would have expected  
> this to generate a compile error.

The line break and comment exist only in the forum message because of  
the way the forum wrapped the unbroken line found in the code.

I discovered the problem. mtime is a datetime attribute in the model  
and an integer in the hash. So I required  
Time.at(hash[:current\_batch][:tx\_batch\_mtime]) for the assignment to  
work.
