Cakephp 3 habtm with additional data - cakephp

While going through a cakephp 3 tutorial about bookmarks and tags I've struggled with a problem: I want to add the third field to the users_tags table (tag_type: important or not), but when it saves the data it rewrites previous values to the default database value of "tag_type".
Could you please help me figure out what I'm doing wrong?

If you added the tag_type column to the users_tags table after running bake commands, check $_accessible array value in entity file of the table i.e. src/Model/Entity/UsersTag.php and add an element with column name as key and true as value to make sure column value can be mass assigned
In your Form html of user add/edit page, add an input like this so that cakephp matches its value with proper column automatically when you create an entity in your controller :
echo $this->Form->input('tags.0._joinData.tag_type');

Related

Drop-Down isn't populated with the 'name' field when table name contains "companies"

I have this very strange issue I cannot explain:
The table drivers has the belongsTo association to the table transport_companies connected by the field drivers.transport_company_id. Usually in the edit|add mode for the table drivers CakePHP generates a nice drop-down with the content of the name field.
The issue:
The drop-drown shows only the ids instead of the content of the name field as long the table has the word companies in it. When I rename the table to transport_firms | transports | transport_units or something else then the drop-down field is populated correctly. I do NOT change anything, I only bake all models each time I rename the table.
My question:
Is there any CakePHP restriction regarding the word companies in a tablename because the drop-down isn't populated correctly?
Greg Schmidt's comment was the important hint. The CakePHP caches got messed up and - according to my another comment - another references began to fail as well.
I avoid this issue running these commands each time I make a change in the database:
bin/cake cache clear_all && bin/cake bake model all
As I don't add any code to the model/table and entity files I can always overwrite all of them. This simplifies the maintenance substantially.

Problem with Showing Query Results on a Form

I'm having a Projects lists Continuous form where the form's Record Source is based upon a table.
I have a requirement to display a field from another table which is linked back to original table using its primary key. The primary key is a AutoNumber field, but when displaying in the form I've used Input mask something like this "TMG/FEA/"0000.
So I made:
a unbound list box
and made the Row source as the query which displays the relevant information from second table
This query was created using primary key displayed in form (I mean the [Forms]![Form Name].[Field] ) as the where clause.
But the results returns blank. I'm Stuck here. I'm not sure if the query is not working due to the Input Mask or because of something else. Please help me. Thanks in advance
You should add to form field listbox, and set following values:
Data: primary key of your first table
After this, that field will duplicate ID value. Now you should transform RecordSource of this field in order to see contents from second table. So you should set:
SELECT [PrimaryForeignKeyID], [DetailedField] FROM tblSecond;. Actually I don't know the contents of your second table. Whereas PrimaryForeignKeyID is a field that links second table to first, so-called FK.
After this set following properties of list box:
ColumnCount = 2
ColumnWidth = 0;2
AllowEdits = False
Save form and open it for viewing.
In this case, your listbox will show the associated contents of second table on form.
So to my mind it is better for you to do such simple tables and forms, and you'll realize idea.

Autofill Form with the ability of entry of new records in the selected fields ms-access-2016

I am currently trying to make a database titled invoice management system for an organization who provide services in different departments. I have created three tables.Tables used in database with fields.
I have then created a query to create an autofill form based on Alias from InvoiceTable and all other fields from AttentionTable except Alias. Autofill Form with Alias from IvoiceTable and rest of the fields from AttentionTable. Alias in InvoiceTable is a combo box whose data source is Alias in AttentionTable. I just want to select Alias (InvoiceTable) from this form to automatically fill the rest of the fields of AttentionTable. Till that point I am successfull. But, I also want to add new record of AttentionTable from this form if the record is not available in the Alias dropdown list. I have tried multiple ways but in vain. I know that i can't enter new record in Alias field because Alias is a foreign key in InvoiceTable. Is there anyway to enter new record in foreign key and update the primary key with this record as I can't enter new records in this field if I need to enter a new record for attention table? I hope you got my point. (Althought I have created new form for first entering record for Attention table and then use this form, but I want All in one in this form)
I hope you help me to resolve my issue. Thanks in Advance.

Load database table in controller cakephp

I made a model for my pre-set database table.
Now in my controller's action, I have:
$this->loadModel('Preset');
$preset = $this->Preset->find();
Each pre-set row in the table has multiple fields, I want the $preset variable to have all the information from one row. How would I search for the row by name and then grab all other fields from it?
Assuming your model is valid:
$preset = $this->Preset->findAllByName('foo');
What you're trying to accomplish is really quite simple and well-covered in CakePHP's documentation.

Cake PHP revisioning data/id refresh

So here is what I am trying to do.
I have one form which will post data to two tables say table a and table b. Now when I edit the same record I want that data in one table should be updated and in other table it should create new row and add the data.
Can anyone tell me how to achieve this in cakephp
Thanks,
When saving, if the primary key (usually id) of the model is given, cakephp will update, otherwise it will insert.

Resources