RE: Help on creation

[prev] [thread] [next] [Date index for 2005/07/05]

From: Andrew O'Brien
Subject: RE: Help on creation
Date: 22:41 on 05 Jul 2005

> I have been looking through the documentation and writing=20
> lots and lots of code that is ugly and never seems to work.=20
> What I need to do it pretty straightforward, so I must be=20
> missing something - and I am hoping someone here can help.=20
>=20
> I have a Class::DBI object called booking with a has_many=20
> relationship to passengers.
>=20
> I need to create the booking object and passenger objects=20
> from a cgi post with the following parameters:
>=20
> | booking.date                          | 2005/7/5
> | booking.departure_time                | 8:00
> | booking.passenger[0].first_name       | Mike
> | booking.passenger[0].surname          | McKay
> | booking.passenger[1].first_name       | Claudia=20
> | booking.passenger[1].surname          | McKay

> But there doesn't seem to be an automatic way to load this. I=20
> have to create the booking, then call add_to_passengers on it=20
> for each one of my passenger elements. This makes it awfully=20
> difficult to write generic loading code. Does anybody have=20
> any suggestions?

<disclaimer>
I'm fairly new the CDBI myself so I'm sure people have better ways but
...
</disclaimer>

By "Generic loading code" do you mean:

1. Code that can handle just the case of any number of passengers for
any arbitrary booking

Or

2. Code that, for any class with one or more has_many relationships,
handles the creation of that object and all related objects nicely


If 1) then I think you're just going to have to bite the bullet and loop
through the passenger list as you're doing now.

If 2) then you do the same thing but you abstract up a layer by
inspecting $class->meta_info() first to see what has_many relationships
this object has, looping through each relationsip and for each of them
doing 1). That's about as generic as you can get.


I'm in the process of finishing a "generic" data editor for internal use
that does pretty much 2) but for all types of relationships and column
field types so if anyone has a better idea I'm all ears myself :)

- ao

Help on creation
mike 16:53 on 05 Jul 2005

RE: Help on creation
Andrew O'Brien 22:41 on 05 Jul 2005

Generated at 16:35 on 28 Jul 2005 by mariachi v0.52