Ok i think i did this wrong.
This is my current collection however I need to order these by percentage.
array (
'_id' => new MongoId("505006de36314b4b27000001"),
'status' => 'pending',
'store_id' => new MongoId("505006de36314b4b27000000"),
'minspendone' => '50.00',
'cashbackone' => '1.50',
'percentageone'▼ => '0.03',
'minspendtwo' => '100.00',
'cashbacktwo' => '3.00',
'percentagetwo' => '0.03',
'minspendthree' => '',
'cashbackthree' => '',
'percentagethree' => '',
'minspendfour' => '',
'cashbackfour' => '',
'percentagefour' => '',
)
so would I better of changing it to the following
array (
'_id' => new MongoId("505006de36314b4b27000001"),
'status' => 'pending',
'store_id' => new MongoId("505006de36314b4b27000000"),
'offers' => array(
'minspend' => '50.00',
'cashback' => '1.50',
'percentage' => '0.03'),
array(
'minspend' => '100.00',
'cashback' => '3.00',
'percentage' => '0.03'))
)
could someone please advise me.
Russell,
If you wish to use the mongodb internal sort function you will need to split the array elements into separate documents.
Mongodb sort works to set the order of whole documents returned, rather the return order of elements within documents.
Hope that clarifies.
Related
Based on following line from CakePHP:
trigger_error(__d('cake_dev', 'Could not find validation handler %s for %s', $this->_rule, $field), E_USER_WARNING);
And rules for the field:
'number' => array(
'required' => true,
'isUnique' => array('rule' => 'isUnique', 'on' => 'create'),
'notBlank' => array('rule' => 'notBlank'),
'maxLength' => array('rule' => array('maxLength', 15)))
CakePHP detects required => true as a rule! When I remove that line, everything works fine!
Note: the field already exists into the data:
$data = array(
'name' => 'xxx',
'fields' => 'xxx',
'startYear' => '999',
'biography' => 'xxx',
'headquarter' => 'xxx',
'number' => '(999) 9999-9999',
'tags' => 'xxx',
'updateTime' => '9999999999'
)
How can I fix that problem?
jeremyharris on this discuss helped me. On CakePHP 2.x the required attribute must be used with a rule; But outside of a rule it will be determined as a separated rule.
Here's the situation:
I have a table which has a composite key:
CREATE TABLE records (
id int(11) NOT NULL,
pacient_id int(11),
doctor_id int(11),
--
-- bunch of stuff that are null
--
PRIMARY KEY (id, pacient_id, doctor_id),
CONSTRAINT records_ibfk_1 FOREIGN KEY (pacient_id) REFERENCES pacients (id),
CONSTRAINT records_ibfk_2 FOREIGN KEY (doctor_id) REFERENCES doctors (id)
)
so far so good, the problem is when I try to add a record... I get this error
Cannot insert row, some of the primary key values are missing. Got (,
, ), expecting (id, pacient_id, doctor_id)
So I went to the add method in the controller and I started put two debugs. One debuging $this->request->data and other debuging $record itself (after the patchEntity) something like this:
public function add()
{
$record = $this->Records->newEntity();
if ($this->request->is('post')) {
$record = $this->Records->patchEntity($record, $this->request->data);
debug($record);
debug($this->request->data);die;
this code was generated with bake.
the result of debug is:
object(App\Model\Entity\Record) {
'others' => '',
'staging' => '',
'surgery' => '',
'medication' => '',
'alergy' => '',
'[new]' => true,
'[accessible]' => [
'*' => true
],
'[dirty]' => [
'others' => true,
'staging' => true,
'surgery' => true,
'medication' => true,
'alergy' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Records'
}
and
[
'doctor_id' => '2',
'pacient_id' => '7',
'points_unusual_lost_weigh' => '',
'points_lost_weight' => '',
'lack_apetite' => '',
'dm' => '',
'has' => '',
'dcv' => '',
'drenal' => '',
'others' => '',
'chemotherapy' => '',
'radiotherapy' => '',
'metastasis' => '',
'staging' => '',
'surgery' => '',
'alcoholic' => '',
'smoker' => '',
'smoker_date' => [
'year' => '',
'month' => '',
'day' => ''
],
'intestine_habit' => '',
'medication' => '',
'alergy' => ''
]
see, after patchEntity there is none _id, but, I really don't know why it's not reaching there.
thanks for those who help!
-- EDITED --
answering the first question below from rrd: yes! I did and it looks like this: (here are my associations)
$this->belongsTo('Pacients', [
'foreignKey' => 'pacient_id',
'joinType' => 'INNER'
]);
$this->belongsTo('Doctors', [
'foreignKey' => 'doctor_id',
'joinType' => 'INNER'
]);
second question from ndm: (here is my $_accessible variable)
protected $_accessible = [
'*' => true,
'id' => false,
'pacient_id' => false,
'doctor_id' => false,
];
Just as assumed, the primary key fields are set be non-accessible/mass-assignable.
Either modify the entity code and remove pacient_id and doctor_id, or set them to true, or use the accessibleFields option in the patchEntity call to override the behavior for the passed entity instance only.
See
Cookbook > Database Access & ORM > Entities > Mass Assignment
Cookbook > Database Access & ORM > Saving Data > Changing Accessible Fields
The debug output of the entity is a little misleading in showing only the *, as this suggests that all fields are accessible. This happens because the "empty" array entries are being filtered in order to have only those fields shown that are actually accessible, which however is obviously a problem when * is used, as the exceptions are lost, so there seems to be room for improvement.
I am adding an item using the following code:
$some_data = array(
'attributes' => array(
6 => $domainName,
1 => $domain->oid,
2 => 705,
7 => 706,
8 => '',
9 => '',
10 => '',
11 => '',
),
);
$some_data = serialize($some_data);
uc_cart_add_item(
$domainProductNID,
1,
$some_data
);
It adds the item to the cart, with the correct configuration. However, if I then go to /cart and click on "remove", the item stays there. I am only able to remove it with:
uc_cart_empty();
Any idea why?
UPDATE
Removing the $some_data attribute and instead running:
uc_cart_add_item(
$domainProductNID,
1
);
Does in fact work... so it must have something to do with the attributes being submitted.
This solved my problem:
$domainProductNID = 27;
$form_state = array(
'values' => array(
'nid' => $domainProductNID,
'qty' => 1,
'attributes' => array(
6 => $domainName,
1 => $domain->oid,
2 => 705,
7 => 706,
8 => '',
9 => '',
10 => '',
11 => '',
)
),
);
$node = node_load($domainProductNID);
drupal_form_submit("uc_product_add_to_cart_form", $form_state, $node);
Hope it helps someone else...
I have array element stored in $sal to put at the start of an array $fields['billing']. i am using array_unshift for this purpose.
$sal = array(
'label' => __('Tratamiento', 'woocommerce'),
'placeholder' => _x('', 'placeholder', ''),
'required' => 0,
'clear' => true,
'class' => array('form-row form-row-wide'),
'type' => 'select',
'options' => array(
'Señor' => __('Señor', 'woocommerce' ),
'Señora' => __('Señora', 'woocommerce' ),
'Señorita'=> __('Señorita', 'woocommerce')
)
);
array_unshift($fields['billing'] , $sal);
array_unshift adding element at the start of array at 0 key index. after print_r i see:
[0] => Array
(
[Label] => Treatment
[Placeholder] =>
[Required] => 0
[Clear] => 1
[Class] => Array
(
[0] => form-row-row-wide form
)
[Type] => select
[Options] => Array
(
[Lord] => Lord
[Lady] => Lady
[Ms.] => Miss
)
)
My problem is only that i just want to change the key value from [0] to ['saluation'], i can simply do that with:
$fields['billing']['saluation'] = $fields['billing'][0];
unset($fields['billing'][0]);
but i also want it at the start of array. i tried many techniques but still unable to figure this out.
this is actully woocommerce fields arrays which i am dealing with.
I just solved it by array_merge() function.
$fields['billing']= array_merge(array('saluation' => $sal), $fields['billing']);
I have a CakePHP TestFixture that imports records from the real database table (into the test database table). However, based upon the CakePHP documentation, it appears that I can also have new records inserted along with the records import. This seems like a totally rational idea, yet it won't work no matter what way I try and structure the declarations.
class MemberFixture extends CakeTestFixture {
var $name = 'Member';
var $import = array('model' => 'Member', 'records' => true);
var $records = array(
array(
'id' => 1999997,
'last_name' => 'John',
'first_name' => 'Smith',
'member_occupation_id' => 0,
'zip' => '',
'age' => 30,
'created' => '2010-10-17 23:18:15',
'modified' => '2011-10-16 23:13:48',
),
array(
'id' => 1999998,
'last_name' => 'Jim',
'first_name' => 'Jones',
'member_occupation_id' => 1,
'zip' => '',
'age' => 25,
'created' => '2010-10-17 23:18:15',
'modified' => '2011-10-16 23:13:48',
),
array(
'id' => 1999999,
'last_name' => 'Dan',
'first_name' => 'Johnson',
'member_occupation_id' => 0,
'zip' => '',
'age' => 41,
'created' => '2010-10-17 23:18:15',
'modified' => '2011-10-16 23:13:48',
)
);
}
I've taken a peak under the hood to see how the record import process works in CakePHP. However, its still somewhat unclear why this functionality shouldn't work. Any thoughts?
'records' => true means that you are importing data from the table, and thus not the ones you have in your fixture
Replace
var $import = array('model' => 'Member', 'records' => true);
With
var $import = 'Member';