On Feb 16, 3:21 am, Frederick Cheung <[email protected]>
wrote:
> On 15 Feb 2011, at 20:26, Mark <[email protected]> wrote:
>
>
>
>
>
> > In the Rails console:
>
> > irb> ts = TableSchema.find(:first, :conditions => "table_name =
> > 'ENTITY_INST'")
> > => [#<TableSchema ID: "88E65D47-621C-4DD6-BD6F-B9ABD93437F8",
> > TABLE_NAME: "ENTITY_INST", DISPLAY_NAME: "Entity Instance"
> > , TYPE: 1, DESCR: "All \"real things\" - by label", DELETED_FLAG:
> > false, CLASS_ID: "085F7B9E-399D-48AD-A7A3-2AD48769F99B">]
>
> > irb> ts.my_objects
> > NoMethodError: undefined method `my_objects' for #<Array:0x47c5830>
>
> > irb> c = Classification.last
> > => #<Classification ID: "3E3A8383-8469-4847-8485-C6761B09FD46",
> > CLASS_TEXT: "UNCLASSIFIED">
>
> > irb> c.my_objects
> > => []
>
> > 1. Why is ts.my_objects not defined, but c.my_objects IS (apparently)
> > defined?
>
> It looks like you're getting an array containing a single object back, rather 
> than that single object. Not sure why.
>

No, I'm getting a "NoMethodError: undefined method `my_objects'" from
"ts.my_objects", and I'm getting an empty array from c.my_objects".

> > 2. c.my_objects should return dozens of MyObject objects.  Why does it
> > return none?
>
> Does the SQL generated (check the log file) look right?

The SQL generated by c.my_objects is:

SELECT [object].* FROM [object] WHERE ([object].class_id = NULL)

Obviously, "class_id = NULL" is incorrect.  My guess is that NULL is
the return value of a call to c.id, and indeed, c.id return nil.  c.ID
returns the correct value.  I think that I need to add a method called
id that returns ID.  Is that right? How do I do that?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to