Per,
Could that be functionality be changed for save? The doc and example
doesn't mention if the record was created by new() or findByKey()
http://cfwheels.org/docs/function/save
Lets say I have action called bookmark and it will go to
bookmark.cfm. The action will set what to display to the user, either
Update or Create bookmark
the form will have <input type="hidden" name="id" value="" /> or with
a value and submit to saveBookmark
I would think save could do the findKey key itself to determine it it
is an update or insert instead of the coder always have to do it.
// saveBookmark - create/update bookmark:
function saveBookmark() {
bookmark = model("bookmark").new(params);
if (bookmark.save()) {
redirectTo(action="main");
} else {
flashInsert(message="Please complete the bookmark form!");
redirectTo(action="bookmark");
}
}
On Jul 26, 4:46 pm, Per Djurner <
per.djur...@gmail.com> wrote:
> No, Wheels knows whether it's a new record or existing one based on
> how it was initially created.
> If created with new() for example Wheels knows that it will eventually
> be inserted to the database for the first time.
> When you use findByKey() on the other hand Wheels knows that it
> already exists and will never try to run an INSERT SQL statement, only
> UPDATE.
>
>
>
> On Mon, Jul 26, 2010 at 10:22 PM, funaroma <
advantex...@gmail.com> wrote:
> > So NORMALLY wheels checks to see if ID exists at all... if it doesn't
> > it performs and insert uponsave(); otherwise it attempts to do an
> > update using the value of .id ? Except in this case, where apparently
> > my aliasing of the id field is breaking that behavior?
>
> > On Jul 26, 12:48 pm, "
tpetru...@gmail.com" <
tpetru...@gmail.com>
> > wrote:
> >> oh ok...
>
> >> that is something that i'm hoping we can automate at some point.
>
> >> when you do an insert (callsaveon a new record or a create) wheels
> >> should see if the primary key has been set (if it's blank). if it
> >> isn't then it should be removed so that you don't have to do that
> >> workaround (which i use myself).
>
> >> On Jul 26, 7:17 am, funaroma <
advantex...@gmail.com> wrote:
>
> >> > Beforesave, I actually have to remove the ID variable from the
> >> > > > > > > > Now, when I try to create a new person, set some values andsave(), in
> >> > > > > > > > my controller, like so:
>
> >> > > > > > > > <cfset objPerson = model("Person").new() />
> >> > > > > > > > <cfset objPerson.vchEmailAddress = params.vchEmailAddress />
> >> > > > > > > > <cfset objPerson.vchSignupSource = "Polls.registerVote">
> >> > > > > > > > <cfset objPerson.save() />
>
> >> > > > > > > > I get one of two errors:
>
> >> > > > > > > > -- When my object is created, id is defaulted to zero. so when I try
> >> > > > > > > > tosaveit, I get this error:
>
> >> > > > > > > > Cannot insert explicit value for identity column in table
> >> > > > > > > > 'MembershipCore' when IDENTITY_INSERT is set to OFF.
>
> >> > > > > > > > (so, it's trying tosavethe id=0 to the database, and (rightfully)
> >> > > > > > > > failing.)
>
> >> > > > > > > > -- If I remove "id" from the "this" struct of Person when a new one is
> >> > > > > > > > created, the record gets saved to the database, BUT the new id created
> >> > > > > > > > by the database never ends up in the person object, so when I
> >> > > > > > > > reference it, I get your standard CF error about the variable not
> >> > > > > > > > existing.
>
> >> > > > > > > > I have a feeling this is the result of "aliasing" the primary key
> >> > > > > > > > field.. but I don't know what to do; I cannot make changes to my
> >> > > > > > > > database schema at all at this time.
>
> >> > > > > > > > What to do? Is there a setting related to the primary key that I'm
> >> > > > > > > > missing?
>
> >> > > > > > > > --
> >> > > > > > > > You received this message because you are subscribed to the Google Groups
> >> > > > > > > > "ColdFusion on Wheels" group.
> >> > > > > > > > To post to this group, send email to
cfwh...@googlegroups.com.
> >> > > > > > > > To unsubscribe from this group, send email to
> >> > > > > > > >
cfwheels+u...@googlegroups.com<cfwheels%2Bunsubscribe@googlegroups.c om>
> ...
>
> read more »