How to Make ActiveRecord always update a field? - mysql

When using ActiveRecord, if you are updating a record, it only adds the fields that have changed to the query. I need a way to tell it to always add a particular field to my query, even if Rails doesn't think it changed. In my example, I always want to set a field to "U" when saving a record. The name of the field is DELETE_FLAG. So, I want to see DELETE_FLAG="U" in the UPDATE query that is sent to MySQL every time.
I've tried DELETE_FLAG_will_change! In the model, but that doesn't seem to have done anything, perhaps because I put it in the wrong place?
I've seen the touch method as well, but this will not do. I don't want to update the record again afterwards.
This seems so basic, I'm sure I must be overlooking something here. Any help would be appreciated. Thanks!

Related

phpMyAdmin not editing correct row

In my phpMyAdmin, when using the built in interface to edit a field in a row, it will always default to an entirely different query in that row.
AS an example, I edit the row with an id of 5, setting the field "health" from 150 to 160, the query that returns is:
UPDATE `database.characters` SET `description`='' WHERE `id`=5
As you can guess, this is very frustrating, as not only has it not done what I've requested, but it's also cleared the description field. Each row in the database has a different behaviour, some will return no query at all, others will edit different fields and some will have no issue whatsoever.
If I construct the query myself everything is fine, but I have designers who want to edit using the interface.
Any help on this matter would be greatly appreciated.

Best way to store ranges and single values in mysql

just facing a little problem right now.
I have a layout-table that contains one field pages. This should specify for which pages the layout should be applied.
The possible contents are "closed" ranges like '3-5' or open ranges like '3-*'. But it should also be possible to add single pages.
So is there a good way to accomplish a content like that
'3-5;11;15;17-*'
in a single field?
Or do you know better ways?
Is there a possibility to query this field like
SELECT * WHERE IN_RANGE(pages, '5') (Pseudo-Code)
I want to prevent creating a table page because it would contain nothing else and also don't want to do the validation in php.
I am happy to provide more information if necessary.
This is a tricky question i dont see "native" sql option for this.
My first idea was to store information about pages as varchar and implement method to tokenize that string so youll have values which you can then process by sql query.

Access filter won't show value list to choose from after 1st filter is set

I'm having a little trouble with the form filter in Access 2007. I'm using the listview in a few forms and the user needs to be able to filter there.
For testing purposes I made a query, which is just based on one table. If I want to set the first filter, it looks like that:
I choose a value and if I want to set another filter (on a different field obviously), there aren't values available to choose from.
This seems to happen only if I use a query (doesn't matter if I use every field, or just a few, based on one table or multiple linked tables). I can of course use the number filter and enter a value manually.
I have another database, where I can use filters when and wherever I want, regardless whether it is a query or a table - I have a list with values to choose from everytime. This means I messed something somewhere up but I have absolutely no clue where.
I'm using Access 2007 (FE/BE), if you need any further details, just ask. Any advice where to start looking is very appreciated!
Well, after playing around for a long while, I figured out what the problem is.
The form recordsource needs to be a query - no sql code, no "select * from query", just the name of a query. Anything else leads to the fact that you are limited in using the filters. I'm not sure if this is a bug or if there is a reason behind this, but that's the way it works in access 2007 - at least for me.
Before I was dynamically adding conditions to my queries which led to a recordsource like "select * from qDeliveries where location = 1". To accomplish this I now just create a temporary query which is the form recordsource instead of just using the sql code.
Hope this helps anyone... :)
Instead of using a query, try this:
File >> Options
Current Database
Scroll down to Filter lookup options
Check ODBC Fields
Close and re-open the file. That should solve the issue.
Create a Separate query and assign to that form. instead of create query within the form. Your problem might get resolved. I did the same way it's working fine for me.

Ordering records with e.g. drag& drop, how does that look in a clean way?

I have no clue how to achieve this, I tried for hours now. I implemented a drag&drop of a list and now I want to save the change of the order in my db. I think for this is an order field needed which stores an int. But the problem is: how should I populate this field?
E.g. I want to do an operation like "insert a new list item after item at position 2", i would define a value higher than that of position 2 and lower than that of position three. But this is limited somehow.
An idea was to write new order values for each record when changing one to keep a clean order value. But that seems odd because it is slow as hell.
How do good systems solve this problem?
I hope, this is what you want
http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=462

How does a user insert a null in MS Access?

MS Access appears to support nulls in code, but I can't for the life of me figure out how to enter a null directly in a table. This is maddening because once a field has had a figure entered in it, it can never be deleted/set to null. Normally, allowing zero length strings would take care of this, but Access treats the XML export of a null and a zero length string differently. A null eliminates the associated XML tag and a zero length string sends an empty tag.
Does setting the "Allow zero length string" option in the table definition help? It may force an empty string to be interpreted as NULL.
Are you talking about needing to do it in Datasheet view? If you needed to do it in an update query, you can do it like this:
UPDATE test SET test.test = Null;
press ctrl-0 and a null is inserted.
Deleting all the characters will work, but Access is a bit fickle. Hitting backspace or delete will not work unless there are characters in the field. I find it is best to enter a few characters, select all, and hit delete, change focus and change the record. After all the above, if you run a query looking for "is null" the record will be found.
I'm actually looking for a way for a layperson to do the entry directly in a table. In MSSQL you can simply press ctrl-0 and a null is inserted. Deleting all the characters doesn't appear to work. Instead of a null, you are left with an empty string. They are not treated the same by Access for export purposes.
I think what I'm going to wind up doing is creating an xslt file to use during export that eliminates empty tags. That way the user can't really tell the difference.
It sure would be nice, though, to be able to key in a null.
Ok, I don't think this is an easily solvable problem and my original question was a little off target. The problem isn't so much with nulls, although they are involved, as with the manner in which the table was originally created. If you use an xsd file to create your tables you plan on exporting, something happens under the hood in Access that causes those fields to be treated a little differently than fields created with the editors.
The only solution I found was to create a new field in the table, rename the old field, copy the data from the old field to the new field and delete the old field.
After doing that, then blank fields that had data in them at one point are no longer included in the XML output. It's probably not the best way to do this, and I still don't know exactly why it's happening, but at least I can get past the issue.
Just delete all characters in the column and access will insert a null value for you if the coumn allows it.