I am trying to Delete the whole data from the CouchDB and again i am trying to write same data with modified **_id field and some extra field **
but i am getting following error :
{
'reason' => 'Document update conflict.',
'error' => 'conflict',
'id' => 'test_1'
},
{
'reason' => 'Document update conflict.',
'error' => 'conflict',
'id' => 'test_2'
},
How to resolve the error ?
When creating new document "test_1", there should be a document with that name already having a different _rev in your db.
If you need to update the old "test_1", you need to provide the _rev of that document when updating. Or else, you can delete "test_1" and then try creating another document with the name "test_1".
The point here is, you should provide the latest _rev of a certain document, when updating that document.
Related
I'm trying to find out how I can have the edit action of a Document (Entity) that is using an array of Object IDs to store the ID of an image stored using GridFS. This is a one-to-many but using an array inside the Document, instead of a middle table.
So far I was able to add the following to my edit action:
Here is the code I've used in the NewsAdmin configureFormFields():
$formMapper
->with('Images Manager')
->add(
'cover_images',
CollectionType::class,
['required' => true, 'label' => 'Cover Images'],
[ 'admin_code' => 'admin.file' ]
)
I have a controller and an action (#Route("/image/{id}", name="show_image")) that handles the display of images in the frontend using MongoDB GridFS. It uses the IDs stored in this array:
I tried several answers from suitecrm forum And here. And I can't implement them to the present version of Suite CRM.
Here is the one I tried last and stuck for further clarification.
add a new file in custom/Extension/modules/yourmodule/Ext/Vardefs e.g. autoincrement.php with the following :
<?php
$dictionary['YOUR_MODULE']['fields']['NAME_OF_AUTO_INC_FIELD'] = array(
'name' => 'NAME_OF_AUTO_INC_FIELD',
'vname' => 'LBL_LABEL_OF_AUTO_INC_FIELD',
'type' => 'int',
'readonly' => true,
'len' => 11,
'auto_increment' => true,
'disable_num_format' => true,
);
?>
and also add unique index for the field in that file
<?php
$dictionary['YOUR_MODULE']['indices']['NAME_FOR_INDEX'] = array(
'name' => 'NAME_FOR_INDEX',
'type' => 'unique',
'fields' => array('NAME_OF_AUTO_INC_FIELD'),
);
?>
Run a Quick Rebuild and Repair in Admin -> Repair and execute the changes.
after that it shows an empty text box. There it iterates automatically, when new account saved. But I want to show the next auto increment number here in this Accounts page itself.
Instead of default value, I want to show the next auto value in the new Account form.
This isn't out the box behaviour - you'll need to add some customisations to do this.
I would create a new vardef auto_inc_preview which is a function type field. This can then be used to grab the largest number from the DB and display this + 1.
A possible issue with this would be that the number a user sees may not be the id that gets generated - for example if two or more people create an account at the same time.
I'm trying to log each action (insert/update/delete) in the application and I'm doing this by getting the dirty and original values after saving the entity. The problem is that all values of the associated entities are returned as dirty and even is_new flag is set to true but actually I'm updating. What causes this behavior and how can I avoid it?
Example:
$data = [
'name' => $name,
'something' => $something,
'Table1' => [
'id' => $idWhereUpdatingTable1,
'field1' => $field1,
'field2' => $field2,
],
'Table2' => [
'id' => $idWhereUpdatingTable2,
'field3' => $field3,
'field4' => $field4,
],
];
$options = ['associated' => ['Table1', 'Table2']];
$updatedEntity = $this->patchEntity($entity, $data, $options);
$save = $this->save($updatedEntity);
// Successfully logging the changes in the main entity
// Trying to log the changes in the associated entities
foreach($save->table1 as $entity)
{
// everything here is set to dirty (even ID field but it's not an insert) and I'm not able to fetch the updated fields only. Also getOriginal() doesn't return the old values.
}
I did some digging into the dirty() function within an Entity and according to the API if you do not explicitly ask it to check a property then it will just tell you if the Entity has any dirty properties.
So doing
$entity->dirty('title'); Tells you if the tile is dirty but running $entity->dirty(); will just tell you if any property in the entity is dirty.
http://api.cakephp.org/3.1/class-Cake.ORM.Entity.html#_dirty
You may want to make code conditional based on whether or not fields have changed in an entity.
For example, you may only want to validate fields when they change:
// See if the title has been modified. CakePHP version 3.5 and above
$entity->isDirty('title');
// CakePHP 3.4 and Below use dirty()
$entity->dirty('title');
I retrieve content types with the following code
$form['ct'] = array(
'#type' => 'checkboxes',
'#options' => node_type_get_names(),
'#title' => t('Hangi tür içerikler hakkında bilgi almak istersiniz?'),
);
And It gives the following output
http://i.stack.imgur.com/TOfS6.png
And when I press Create new Account button, the POST Array is so :
http://i.stack.imgur.com/BtxhC.png
My Question is How can I insert into database these values and read?
There are two ways of saving this data and associates with user ID ($user->uid).
Adding a new field for users from 'admin/config/people/accounts/fields'. Say the new field name is 'ct' and it is a list type field. In hook form_alter you can assign this options to 'ct'. Drupal will take care of saving the data.
You can create separate table to keep this information and use db_insert function in hook hook_user_update. To retrieve this information you need to use db_query in hook_user_load.
I have a database table "transactions" which has a field "account". I want to retrieve a subset of all not-null account rows from the current set of data and have it as a virtualField I can access down the line in my view.
class Transaction extends AppModel {
public $virtualFields = array(
"Accounts" => $this->Transaction->find("all", array("conditions" => array("not" => array("Transaction.account" => null))))
);
}
So that I get an array of all transactions with non-null account fields named "Accounts".
This doesn't work - gives me "unexpected T_VARIABLE" error (doesn't like $this). I was trying to follow the guide here. I'm a moderate level PHP developer and this is my first real Cake project, so I may be going about this completely wrong.
When you're inside the model that you're querying, you don't specify the model name, just:
$this->find('all'); // when you're inside transaction model
...so try this:
"Accounts" => $this->find("all", array("conditions" => array("not" => array("Transaction.account" => null))))