Difference between setValue() and updateChildren()? - firebase

I have done research about setValue() and updateChildren(). I have tested both of them to add and update data from firebase database. From what I have learnt that both of them did the same exact thing and did some research about them.
From what I have learnt. The setValue() is used with a class object while updateChildren() is used with a Map or HashMap. Correct me if I'm wrong.
My question is as stated above, what is the difference between setValue() and updateChildren()?

'setValue' method is totally replacing the document (specified reference) with new data.
'updateChildren' method is just updating particular fields or add such fields if they did not exist before.
You often can get the same result using those methods, but actually they are different.

Using an example where your user has fields: Name, Birthday, Favourite Colour.
Set value requires you to set all the fields under the same parent node otherwise they are overwritten with no values and deleted.
However, using updateChildValue, you can specify which field you would like to update without altering other fields. And, if the field doesn't already exist, it will create a new field. This is especially useful if you just want to add a new field under the user like hair colour.

Related

Get request data (GET) in a Symfony (5) formType without using data_class

I'm building a formType to filter products on a collection page. You can set multiple select boxes which makes other auto filled or unnecessary. I want to be able to manipulate the formType based on the data like when using a data_class object. I'm not using data_class because the search isn't a persisted object which is saved to the database. I'm using a GET form.
For example 2 select boxes:
category
productType
When setting a category makes some of the productTypes unnecessary. So i want to not show it.
To do so in the formType I need the data of the request (GET) but I can't find a way to do so.
To retrieve data from the form, you can use $form->getData().
As you're in a GET context, I suspect you can take advantage from FormEvents (take a closer look to POST_SET_DATA event) and get rid of values you don't need.
One other thing I would like to point out, is that you still can use some kind of object that's not persisted to DB, like DTO or whatever.
Forms and entities are not related anyhow, neither in the usage nor in the intentions.

Manually set the current item in a form

What is the code to manually switch a form to a specific record? I was trying to use relations but I can't make a relation to a calculated table, which is where this is coming from, so I have to hardcode which data is populated.
I'm looking for something like
onLoad()
(read the ID from page properties, which I use for globals)
widget.item.select(id);
I think you would want to use:
widget.datasource.selectKey(id);
This works on the assumption that your record is currently loaded in your client however. If your record is not loaded then this will not work.

AX 2012 initFrom methods

I understand that these initFrom(TableName) methods are to initialize fields in a table for related tables. Where are they called from? I want to follow this pattern but where do I call this method?
Every documentation on this pattern just tells me what I said above and no examples of using them. I see examples of them being created.
Maxim Lazarev made a point about using the cross-reference tool. I ignorantly did not realize that you had to update it on the table and then you can see what calls on that method. That lead me to examples of it being used in overridden table methods like modifiedField. I'm starting to play around but it looks like I can now use these initFrom methods to fill in specific data I need in forms whether it's directly in the table or in the actual form itself.
The initFrom methods are to initialize the record based on another record. They are not called automatically, you can use them yourself
though.
For example PurchTable.InitFromVendTable() sets all the relevant values from the vendTable to the (new) purchtable record. So if you want to create a Purchase Order and you have the vendor, you can use this method to set the correct values.

Complex Rule in Drupal involving multiple entities

I need to create a fairly complex rule in Drupal - I am willing to use either code or the interface to do so.
I am more familiar with the interface, however, as opposed to the Rules API.
Anyway, the rule will be as follows:
It will happen based on a form submission from entityforms (which is one entity). It will take the checkbox value of a field (not just the true or false, but rather the value submitted when a value is true or false). It will convert this number to an integer.
At this point things get interesting - I want to create a new entity of registrations (a different entity), which as far as I can tell, means I'll have to bring a registration into scope. I also need to bring node (and not just node: type and other data selectors, but specifically node) into scope, because the next step requires it.
So at this point, I should have three entities loaded into scope:
entityforms
registration
node
I believe the best way to bring registration into scope would be entity is of type? The documentation page says that content of type should be appropriate - but that seems like it might be related to the specific use case of the example - not in my more complex example where registration isn't the first entity dealt with, but rather a second.
https://drupal.org/node/1463042
So anyway, if all three of these entities is called in correctly, the ultimate result should be the following:
Value from boolean field (not the straight 1 or 0, but whatever the value to be submitted is switched to) from the entityform is converted to an integer, and inserted where entity host ID is required. In the section where host entity type is the value should be node.
I am also open to alternative suggestions if this seems overly complex or poorly architected.
The Host Entity Type cannot be of Entityform? Why be a Node since a Registration can be attached to any entity? Then you will get the id of the Entityform as also as any other fields from that entity type instead of Node. Next steps are the same.

Is there documentation for non-dynamically adding a 'many' to a 'one' in a 'one-to-many' relationship?

I have a Customer who has several PhoneNumbers.
The user creates a new Customer via a form, and I want him to be able to specify a single PhoneNumber.
Symfony's documentation tells me how to do this if the user were creating a PhoneNumber and had to also specify a Customer (link). It also tells me how to solve my problem using some Javascript, as described by the Cookbook's recipe for dynamically adding entities (link).
What I'm missing is the part of the documentation where it simply describes a non-dynamic form that lets you add a single entity upon submission. So, the user fills out the customer's details, puts a phone number, and everything works out.
I suppose I could make a separate form, give it a PhoneNumberType, and then upon submission, call $customer->addPhoneNumber($phoneNumber). But it seems like there should be a way to handle it through the relationships alone & in a single form.
Coming back to this question, I realize the answer is simple. In my controller,
// CustomerController.php
$customer = new Customer();
$phoneNumber = new PhoneNumber();
$customer->addPhoneNumber($phoneNumber);
Now when I build my form, I'll have a single blank PhoneNumber associated with the new Customer, and everything will persist as expected.

Resources