On Tue, Nov 12, 2002 at 07:09:28PM +0000, Michael Styer wrote: > I've just been introduced to Class::DBI. While I like it lots in general, > it seems like it's missing one obvious featur
> So what I wanted to be able to do is this: > my $survey = Survey->retrieve($survey_id); > $survey->add_question(\%question_data); > where the 'add_question' method is created automagically Very interesting approach... > rather than having to do this: > my $survey = Survey->retrieve($survey_id); > my $question = Survey::Question->create(\%question_data); > $question->survey($survey); Technically, if you were doing it this way, you should probably do: my $survey = Survey->retrieve($survey_id); my $qn = Survey::Question->create({ %question_data, survey => $survey }); as some databases might complain that you're violating the schema at the initial create (as your foreign key is null until the next statement). But I definitely like the first approach. > I don't like this because I have to hard-code the name of the child > class somewhere else besides the has_many initialization statement, > and that feels messy. It also just feels backwards. I'd be interested as to why you think it feels backwards... > I've overridden 'has_many' with a version that does what I want, but my > question is, am I missing a trick? Is there a standard idiom for doing > things more or less the way I wanted to within the existing Class::DBI > framework? I don't think so. Would you mind submitting a patch? Thanks, Tony