[prev] [thread] [next] [Date index for 2005/02/02]
--- Josef Chladek <j.chladek@xxxxxxxxxxxxxxxx.xx> wrote:
>
> Am 01.02.2005 um 18:09 schrieb Peter Speltz:
>
> > I was thinking override create_from_cgi. you should just be able to
> > put a sub
> > in your base model class (or just class you want the override) called
> > create_from_cgi.
>
> ok, so i did, this opens a can of worms for me:
>
> sub create_from_cgi {
> my $class = shift;
> my $article = $class->SUPER::create_from_cgi(@_);
> my $textblock = Article::Textblock->create_from_cgi(@_);
> $textblock->article($article->id);
> $textblock->update;
> $article;
> }
>
> with this i was able to insert the title, lead along with one block in
> the two tables.
>
> 1) i hardcoded the formfield in the addnew template, how could this be
> done automatically? Article::Article->columns(All => qw/title lead
> block/) is not the way, it of course tries to retrieve the value of
> block in the article table
> 2) related to this, what has to be done in the edit template
> 3) what about multiple blocks? how should the formfields be named
> (block -> i get an array), block1, block2 ... -> this breaks the
> automatic insertion)
>
>
Alright!. I'm working on this today too. We can work together. Do you use
AsForm?
Here's where i'm at on mixing of tables in create. I've spent a lot of time on
this and code is mostly done. just details to work out.
1) AsForm should make foreign inputs (as i call them) automatically when it
knows too.
? How does asForm know to make inputs ?
Ideally it should know from 1 to 1 relationship declarations. Otherwise you
might as well call it yourself with the foreign class. Two one to one
relationships in cdbi: might_have (but this is a 0-1:1 so we don't know if we
really want inputs or not) and has_a (but this is really a 0-M:1 so we have a
problem).
Solutions:
1. "has_one" -- a new relationship that is just like might_have but no
might. maybe "must_have" would be a better name?
i posted has_one for testing in this thread
http://groups.kasei.com/mail/arc/cdbi-talk/2005-01/msg00136.htmlrevisited
2. for has_a relationships a hint could be passed in args to indicate this
is a one to one rather than an 0-M:1. Then asform could make inputs rather than
a select box.
? How should it name those inputs ? Where should it put them in the hash
it's returning?
So a call "create_from_cgi($r->params)" or "create($r->params)" will be able to
create all components of an object. It could put them in a hash keyed on
accessor name. That's what my AsForm does now. Then the templates expand the
hashes with a FOREACH to display the inputs. We need a naming convention that
create_from_cgi and create will recognize. I've thought about
"accessorName__AsForeign__columnName" . Then in the create* call the input name
could be split on "__AsForeign__" and you'd get accessor and column. the class
can then be derived from meta_info for teh accessor (see output of
$class->meta_info as its undocumented) and another create_from_cgi or create
call could be made with that class.
However, if one wants an arbitrary number of same object like Josef, say for a
has_many relationship, it gets weird. I don't know what to do here. With my
has_one and might_have relationships i can do this :
has_one(main_block=> 'Block' ...);
# input names for cols for this element could be : main_block__AsForeign__*
has_one(block0 => 'Block' ...);
might_have(block1 => 'Block' ...);
might_have(block2 => 'Block' ...);
Currently a call to my AsForm::to_cgi method with this setup up would return:
{
main_block => { col1 => htmlelement ...},
block0 => { col1 => ...},
...
}
but it could easily format names and put all in top level hash:
{ main_block__AsForeign__col1 => htmlelement,
main_block__AsForeign__col2 => ...,
block0__AsFor...
}
Except with them in hashes by accessor Templates can tweak input names
easier. Don't know. I kind of like the later better as i use FromCGI.
Thoughts?
=====
pjs
__________________________________
Do you Yahoo!?
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250
|
Re: [Maypole] mixing of tables in create
|
Generated at 11:20 on 20 Feb 2005 by mariachi v0.52