Newsletter flag set to 2 in db column? - cakephp

I want to set newsletter flag to 2 in database table, but when I do this $this->data['User']['newsletter'] = 2; It always sets to 1. Its a checkbox on registration page. Can anybody help me how to set it to 2.
Thanks!

If it is a checkbox, you got your newsletter field to tinyint(1). which is a boolean representation of yes/no, 1/0.
SO either you only want to store a boolean value (and therefore the checkbox in the view) or you need to change your field to tinyint(2) to allow some kind of enum (more than just two definite states). But then you also need to use a select here in the view.
So what exactly are you trying to do? You can't have it both ways.

Related

Two-way synchronization between View Objects

I have two view objects in Oracle ADF.
LineVO represents order lines -- with one line per product.
Products are differentiated by several attributes... say "model" and "color". So, VO #1 contains a row for each model/color combination.
ModelVO represents a model-level summary of the lines.
Both VOs have a "quantity" field (an Integer).
There is a ViewLink between them and each has a row accessor to the other.
I want to achieve two-way coordination between these two view objects, such that:
When a user queries data, ModelVO.Quantity equals the sum of LineVO.Quantity, for the associated rows
When a user updates any LineVO.Quantity, the ModelVO.Quantity is immediately updated to reflect the new total
When a user updates a ModelVO.Quantity, the quantity is spread among the associated LineVO rows (according to complex business logic which I hope is not relevant here).
I have tried many different ways to do this and cannot get it perfect.
Right now, I am working on variations where ModelVO.Quantity is set to a Groovy expression "LineVO.sum('Quantity')". Unfortunately, everything I try either has the summing from LineVO->ModelVO working or the spreading from ModelVO->LineVO working, but never both at the same time.
Can someone suggest a way to do this? I want to do it in the model layer (either a EO or VO or combination).
Nevermind.. it turns out to be simple:
ModelVO.Quantity must be set to a Groovy "LineVO.sum('Quantity')" and it must have a recalcExpression set to a method where I can control things so it only recalculates when I am changing a LineVO.Quantity value.
The reason my approach didn't work initially was because, when the user updated a LineVO.Quantity value and I wanted to recalculate, I was getting the ModelVO row by lineVORow.getModelVO()... i.e., via a view accessor.
Apparently, that returns some sort of internal copy of the row and not the actual row.
When I got the parent row via the applicationModule.getModelVO().getCurrentRow(), the whole thing works perfectly.
I've posted another question about why accessing the row via the view accessor did not work. That part is still a mystery to me.

Why some properties of dial in tab stored in two attributes?

Verify Caller ID of dial-in tab in user object stored in two attributes(msNPSavedCallingStationID and msNPCallingStationID).But two attributes values are same.why they store same values in two attibutes?what is the use?what is the difference between msNPSavedCallingStationID and msNPCallingStationID?
I ran some tests and determined that the value of msNPSavedCallingStationID is what is shown by Active Direcotry Users and Computers when viewing properties of the user, msNPCallingStationID is the actual value used.
As to why this is the case, I can't say, perhaps msNPCallingStationID changes temporarily?

Table with dummy row (ID 0) and auto increment index

Is it legal/okay to create a row with ID '0' and AFTER that set auto increment of that ID column to (1, 1)?
Why do I ask this?
I have a table Products with columns ID and Name. I want to show all Products inside my application in a ComboBox. Users can select a product but the default entry should not be 'Product 1' but something like '(Nothing selected)'. Is it okay to create a 'dummy row' with 'ID = 0' and Name = '(Nothing selected)' in database so the application will automatically display it as default selected item?
I think the better solution is to programmatically add a please select option and validate against it, assuming you don't really want users to have this selected? I guess in theory what you've proposed should be OK though? You'd have to be careful retrieving the values in order of their Id though, if you ordered them by name you'd have to ensure you pulled Id = 0 first then ordered the rest which feels like more work then programmatically adding the option where needed to me.
If your users can have nothing selected then programmatically add the nothing selected option and handle saving no value if it is selected. Otherwise you're saving data that represents no data really which could be deemed a waste of memory.

How to set value in a field by UI?

I use three fields in Sqlserver Datavbase tables, for prevent delete records permanently by user:
IsDelete (bit)
DeletedDate (DateTime)
DeletedUserID (bigint)
I wish to set third field (DeletedUserID) by UI by some thing like this:
this.ExamdbDataSet.AcceptChanges();
DataRowView row = (DataRowView)this.BindingSource.Current;
row.BeginEdit();
row["DeletedUserID"] = User.User.Current.ID;
row.EndEdit();
this.ExamdbDataSet.AcceptChanges();
row.Delete();
and other two fields ,'IsDeleted' field and 'DeletedDate' are set automatically in table's 'After Delete Trigger'.
then commit changes to database with desire command successfuly with this code:
this.TableAdapterManager.UpdateAll(this.ExamdbDataSet);
but problem is , the 'DeletedUserID' is null in database.
and Question is : How to set 'DeletedUserID' field value by true way in UI?
I don't think it is a good way to do that. You have sliced a simple logic to separate parts, each being done in a different part of the application (UI, Trigger, ...). You set value of some field, and then DELETE the whole record! Don't expect anything else that the current situation.
You would better set all fields in UI (i.e. no trigger in this case), and change the query that loads data. For example,
Select * from table1 where IsDeleted=0
You didn't tell us anything about whether your use ASP.Net or WinForms. Give us more info.

cakephp setting select options and values at Model

In my database model, my attribute is set as type INT.
On the front end, I want to display a select field with representative values for the respective Integer values.
eg: [1 = Home, 2 = About]
I am currently using an external plugin for the administrating content, and the select values only allows integer. So my idea is to achieve this at respective Model. Is it possible?
Genarally yes.
You should be able to attach results of Model->find('list') to select field. Of course your model should have name or title fields for description values (Home, About).
Sounds like the kind of enum representation as I always use.
Try this solution:
http://www.dereuromark.de/2010/06/24/static-enums-or-semihardcoded-attributes/
I basically uses an array matching to resolve those ints into strings in a clean way - using the model. can be the whole array for select fields or just the specific string for output in the view/index.
Its also fully form and bake-template capable.
If you name the field "attribute" in your table, and name the method "attributes()" you can easily have "cake bake" to bake this via custom templates.

Resources