the magic under the covers to figure out if the record exists already
or not.
When you do the "save", Cake does a lookup to figure out if the
request needs to be an insert or delete (assuming you have the
constraints set properly).
I would expect that whether you can take advantage of this is entirely
dependent on the data you are getting sent. If your customer
information includes a unique key, then you should be able to use that
as your ID, and Cake will automagically do an insert or update. If it
doesn't give you a primary key, you'll need to do a lookup and figure
out if you want to do the insert yourself anyway.
On Dec 25, 2:37 pm, "Chad Casselman" <ccassel...@gmail.com> wrote:
> Let's see if I can explain this better.
>
> I have the models setup correctly or so I think - new to all of this.
>
> But I am getting lots of information posted from an external source so let's
> say field1, field2, field3, etc. etc.
>
> Fields 1-10 are customer information
> Fields 11-15 are product information
> Fields 16-20 are order information
>
> I need a script the can accepted the above fields, but the catch is for me
> to check to see if the customer exists, if not add it. Then check to see if
> the product exists, if not add it, then the same with the order. I don't
> understand how the current magic save stuff works - because it is all hidden
> from me. I need to see it working to understand it, but most examples just
> say use it. I am not using it the typical way so without understanding it,
> I am struggling to create the script to accept the posted information.
>
> Does that help or hurt?
>
> Chad
>
> On Thu, Dec 25, 2008 at 3:02 PM, Webweave <webwe...@gmail.com> wrote:
>
> > So are you saying you're getting data posted to you somehow that isn't
> > related to the tables you outlined?
>
> > I'm not clear on whet you mean by "I can't control the name of the
> > fields coming in", but it sounds like you have the basic idea.
>
> > Cake should handle the magic for you as long as you build the table
> > structure, model and relationships properly.
>
> > All you need to do is build the Model structure into $this->data, and
> > do a saveAll (or save for each bit you are interested in). There are
> > lots of examples on how to do this floating around.
>
> > On Dec 23, 8:11 am, "Chad Casselman" <ccassel...@gmail.com> wrote:
> > > Very new to cakePHP and of course the first thing I try doesn't follow
> > the
> > > model.
>
> > > I am trying to create a script which takes a lot of post variables (from
> > > 1shoppingcart exactly) and then puts them in the corresponding values in
> > my
> > > database design.
>
> > > Let's say my database is:
> > > customers
> > > customers_products
> > > products
>
> > > I haven't figured out exactly how to do the associations but that is not
> > my
> > > hang up right now.
>
> > > I can't control the name of the fields coming in, but I need for the
> > > save/post to go through the data and put the customer info into the
> > customer
> > > table (always new inserts), then go through the product information
> > (unknown
> > > count) (product1name, product2name, etc) and put them in the product
> > table
> > > (record of source) if they do not exist and then connect the customer to
> > the
> > > products that they ordered.
>
> > > I am completely stumped on how to even tackle processing form information
> > > that was not generated by cake.
>
> > > Chad
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment