| Bill,
Not sure what's to disagree with... you picked the exact scenario I did to exemplify why this WOULD work. ;) Besides, I never drew any conclusions! I was just mulling the things that occurred to me as I read Doug's posts since he asked for thoughts.
What makes me uncomfortable is the fact that whey you start treating individual columns as viable individuals instead of members of a larger set of data you lose touch with the whole concept of a "record" and, while it may be handy, potentially introduce other problems. At least it "feels" that way.
Let me take a slightly different angle on this and see how I feel about it:
<cfquery name="addUser" datasource="#someDsn#"> <!--- DAMN it's been a long time since I typed that!!! ---> insert tblUser (userId,fname,lname,addr1,addr2,city,state,zip,hasValidated) values ( [not I'm NOT typing in all the cfqueryparam tags... why do you think I wrote SQLSurveyor?!?] ) </cfquery>
Now, if I have other, nullable columns in that table... like profileImageFileName...
HMMMMM... that's interesting. Nullable columns. See, this really is all stream-of-consciousness. You're getting this as I'm thinking. :)
Anyway, if I have a BASE BLOCK of columns that ARE the record and the other things aren't mandatory... alas this will take further thought.
I must go refill the coffee cup and ponder. :)
Laterz!
------------------------------------------------ Jared C. Rypka-Hauer Continuum Media Group LLC http://www.web-relevant.com Member, Team Macromedia - ColdFusion
"That which does not kill me makes me stranger." - Yonah Schmeidler On Feb 9, 2006, at 12:18 PM, Bill Rawlinson wrote: I have to respectfully disagree with Jared. I think it is totally viable to only update a portion of a record at a time. And since he was so willing to proide scenarios I will too.
Lets imagine a bug tracking application which has a bunch of projects in it - each project has a bunch of toggle-able settinsg such as "allow_anonymous_viewing" and "supports_cost_accounting"
Now this application has a user interface that lets the user quickly toggle these settings one at a time OR to go in and fully edit the project. When the user goes to fully edit the project then sure the whole record needs to be written to the database but, when toggling just one value at a time why would you want to read the entire project data down, change one setting, then update the entire project record again when the process could have just involved updating that one setting where projectID=x?
sure, the same app might have the project information cached in the users session; but it might not (for who knows what reason). Should the application have to make the extra trip to the database to populate some bean just to update a single column in the record? I don't think so. I think it would be terribly inefficient.
Bill
On 2/9/06, Jared Rypka-Hauer < [EMAIL PROTECTED]> wrote: Thought 1: Danger, Will Robinson!
Thought 2: Danger why?
Thought 3: Hmmmmmmmm...
Scenario: I have a preferences page with 2 checkboxes that represent bit columns in my database. I have a primary key (say userPrefsId) and 2 bit values (say... rememberMe and sendMeJunkmail). This is one page from my "Profile" section of the site. Why update a whole set of records when I have the ID and values and don't really need anything else or to update anything else.
Scenario: Change Password form. I have my AccountId and 2 password fields in my form. All I need to do is validate, hash() and save the password value. Why not just use the AccountId and password fields in the Account object? Why update a dozen columns when I only need to save 2?
Then it becomes possible to do something like this:
<cfset Account.save(arguments.event.getValue("fieldnames"))>
OK... so it looks viable at first blush. So what could go wrong? Well, obviously there's the matter of unsatisfied dependencies, which means that not only would save() need to be able to take a list of values to publish to the DB, but validate() would need to take that same list, I think. How else would you make sure that dependencies are satisfied before writing part of your record object to the DB?
Another thing that's nagging at me is the fact that a "record" is a whole. It's the smallest part of the data in the DB. Sure, there are component parts... think of a record as a molecule of data, comprised of protons, neutrons, defaults and foreign keys. So, is it really a GOOD idea to go around only saving pieces of this record to the database at a time? Something's disconcerting about that. My "gut hunch" is saying that if you have an object that represents a row in the DB, the whole row should be written out at once because the whole row IS the smallest cohestive unit... the columns are components of that row, sure, but they have no meaning or value outside the context of a whole row taken at once... hence the concept of a record.
Hey, you asked for thoughts... you never said they had to be concise, or even make sense! ;)
Laterz!
------------------------------------------------ Jared C. Rypka-Hauer Continuum Media Group LLC http://www.web-relevant.com Member, Team Macromedia - ColdFusion
"That which does not kill me makes me stranger." - Yonah Schmeidler On Feb 9, 2006, at 10:02 AM, Doug Hughes wrote: <delivery mode="nicest way possible">Argh!</delivery>
You know. I more or less rudely shot you down. But now that I've done that (and you politely took it) I've been thinking about ways to do this.
The load and delete methods take various arguments to indicate what to load or delete. Why not something akin to that for saving? IE:
<cfset myRecord.save("list,of,fieldnames") />
Something like that might save only the specified fields for that record? Of course, if you have constraint issues it'll throw an error.
That seems like it might be handy. Thoughts?
Doug
Doug,
Thanks for the great code and quick response. I appreciate both.
I'll simply add the methods I need. If it appears to be useful and reusable, I'll forward you the changes.
Thanks, Chris
Nope – There's no way built in to do this (unless you have a two column table).
I can't make reactor everything to everyone. You're welcome to add your own methods to do what you need, as you need it.
Doug
After digging through the docs and DAO, I was unable to find a way to update a single value (rather than updating every value in the table) using Reactor. Is there a built in way to handle this, or will I have to extend the DAO?
Thanks, Chris
-- [EMAIL PROTECTED] http://blog.rawlinson.us
If you want Gmail - just ask. |