Thank you both for the suggestions. I hope you don't mind me digging a little deeper as I am fairly new to Rails and Hobo.
I guess the this keyword could work. In answer to your question Matt, Topics and Themes have got names and descriptions (plus the customary IDs). So maybe that's an option - could you tell me more about your "virtual attributes" suggestion? But maybe Kevin's suggestion is easier? Kevin, could you tell me a little bit more about your suggestion "do an after create callback or some other custom creation of the topics after the fact." You mean create some custom method and tie that the the event model definition? What did you mean about "custom creation after the fact"? Thanks so much for the pointers, I'm really glad this community is here to help as there is not a lot written down about Hobo! Regards Alex On Mon, Feb 22, 2010 at 5:06 PM, Matt Jones <[email protected]> wrote: > > On Feb 22, 2010, at 4:22 PM, Alex Bowyer wrote: > > Hi, I have a data model like this: >> >> event >> has_many :topics, :accessible => true >> has_many :themes, :accessible => true >> has_many :sessions >> >> basically, if an event has 2 themes and 2 topics, it will have four >> sessions: >> (topicA+theme1, topicB+theme2, topicA+theme2, topicB+theme1) >> >> I am modifying the "new" action and I want to add some code to create >> these session objects after the user saves their new event. >> >> I assume I want to do something like this: >> >> def new >> hobo_new >> # eventid = id of newly created event (how do I do this) >> themes.each do |theme| >> topics.each do |topic| >> session = Session.new >> session.event_id=eventid >> session.topic_id=topic.id >> session.theme_id=theme.id >> end >> end >> end >> >> What I can't figure out is how to get the id of the newly created >> event so that I can use it when creating the child session objects. >> > > Inside the hobo_new block, you could use the standard 'this': > > def new > hobo_new do > if this.errors.empty? > event_id = this.id > > themes.each do |theme| > topics.each do |topic| > session = Session.new > session.event_id=event_id > > session.topic_id=topic.id > session.theme_id=theme.id > end > end > end > end > end > > But that's quite a mess to do in a controller, so I tend to agree with > kevinpfromnm that this belongs in a model callback. > > I'm also curious as to how much functionality is actually attached to the > Topic and Theme models - are they just basic [id,name] tuples? You might be > better off not even creating models for them, and just setting up some > virtual attributes that handle setting up the sessions. > > --Matt Jones > > > -- > You received this message because you are subscribed to the Google Groups > "Hobo Users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<hobousers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/hobousers?hl=en. > > -- ============================================ Alex Bowyer Email: [email protected] Skype/ooVoo: alexbowyer Personal blog: http://alexbowyer.blogspot.com/ Professional blog: http://www.bitcurrent.com/ "Be obscure clearly" ============================================ -- You received this message because you are subscribed to the Google Groups "Hobo Users" 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/hobousers?hl=en.
