2009/9/14 doug <[email protected]>: > > The following short console session illustrates the problem: > > Loading development environment (Rails 2.3.2) >>> topic=BlogTopic.find(4) > => #<BlogTopic id: 4, parent: 2, topic: "Topic Four", created_at: > "2009-07-13 21:31:22", updated_at: "2009-09-14 00:37:29"> >>> topic.inspect > => "#<BlogTopic id: 4, parent: 2, topic: \"Topic Four\", created_at: > \"2009-07-13 21:31:22\", updated_at: \"2009-09-14 00:37:29\">" >>> topic.parent > => #<BlogTopic id: 2, parent: 0, topic: "Topic Two", created_at: > "2009-07-13 21:29:02", updated_at: "2009-07-29 21:11:46"> >>> > > The variable 'topic' is supposed to get an instance of the BlogTopic > object corresponding to the DB record with and id of 4. The console > initialization seems to indicate that that happens and the > 'topic.inspect' in the second line confirms it. > > In the third and final line, I would expect topic.parent to return '2' > as the record value for the parent field. Instead, I actually get the > full entire parent record. I should say that I am using acts_as_tree > and 'parent' is my foreign key. I'm thinking that might have > something to do with it.
If you were to use parent_id as the field name, which would be more conventional and arguably more intuitive, then topic.parent_id would give you the id and topic.parent would give you the object. As an aside I have found that when I find myself manipulating the ids then often it means I am not doing something the best way, not always but often. Very often rails can do a lot of the magic for me, removing the need to use the ids. Colin > > Anyway, I'm trying to figure out why this is happening; and, how I can > get at the value of the parent field in topic. Anyone have any > suggestions? > > Thanks for any input. > > ... doug > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

