The solution below, props to dkubb. thanks. [12:20pm] taerb: anyone here using DM with Rails? [12:23pm] stepheneb left the chat room. [12:24pm] dkubb: taerb: no, but I've seen it done before. are you having problems with it? [12:24pm] taerb: kinda... can i give you a link to look at? [12:25pm] dkubb: taerb: sure. did you just post on the mailing list? [12:25pm] taerb: google groups [12:25pm] taerb: http://groups.google.com/group/datamapper/browse_thread/thread/d4308f62a56cbc3c# [12:25pm] dkubb: taerb: right. I saw that [12:25pm] taerb: its so weird [12:26pm] dkubb: taerb: as a small test, at the top of your post.rb, can you explicitly require the comment model? [12:26pm] taerb: sure [12:26pm] taerb: one sec [12:26pm] dkubb: taerb: I just want to rule out the possibility that the model load process in Rails is borked [12:28pm] taerb: holy crap [12:28pm] taerb: that worked [12:30pm] dkubb: taerb: good. at least we know what the problem was [12:30pm] dkubb: taerb: I think it has to do with how Rails lazy loads the models on their first access [12:31pm] taerb: gotcha
On Jan 20, 11:21 am, taelor <[email protected]> wrote: > Hey guys, > > With the upcoming merger between Rails and Merb, I have decided to > change my blog back to Rails from Merb, but still use DataMapper > instead of ActiveRecord. > > Everything has worked fairly smoothly, except one thing. I have a has > many relationship between Post and Comments. When I try and do > @post.comments, I get an error... > > "Cannot find the child_model Comment for Post" > > What's weird is in my controller, if I have something like... > > @comments = Comment.all(:post_slug => params[:id]) #params[:id] is > the title slug, which is the primary key for post > > then @post.comments works. > > So I think it stems from something in my model definitions, which can > be here... > > http://pastie.org/365781 > > Now, this code worked in Merb, and let me use the @post.comments. I > think it has to do with the fact that my primary key for my Post is > the slug, and the foreign key is called post_slug in the comments. Is > there something I need to define when I say has n, :comments or > belongs_to :post? something like child_key => "post_slug" or > something? > > I think its so weird that in my contoller if I search for the > @comments, and don't even reference it, its ok to say @post.comments. > I would love to know why, just for my own knowledge. > > Any help would be most appreciated. Thanks! > > (BTW to give back to the community, I will write a blog about setting > DM up with Rails and this fix included) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "DataMapper" 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/datamapper?hl=en -~----------~----~----~----~------~----~------~--~---
