The way you've laid it out, it can't be done without saving the event and related before this. Instead, you might want to do an after create callback or some other custom creation of the topics after the fact.
I was going to say use the association new method but I don't know of anyway to link one model to 3 other unsaved models. perhaps you could do this in your loop session = this.session.new session.topic = topic session.theme = theme I have no idea if rails handles multiple associations like this correctly or if it'll make a mess things. On Feb 22, 2:22 pm, Alex Bowyer <[email protected]> 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. > > Any advice would be greatly appreciated > > Thanks > Alex bowyer -- 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.
