Adding antoher fields in TranslateBehavior in CakePHP - cakephp

I use TranslateBehavior in my app.
Model translate fields like name, content and slug. The table has many records.
...and now I must add antoher field to this table and I have problem. When I added field name to actsAs in model, my records return empty results. Why?
How add another field to Translated model after fact?

At first, I suggest you try to clean the model cache (delete files from path/to/project/app/tmp/cache/models.

I ran into the same problem.
The solution was to execute a SQL query to create the new translated fields that should have been created before.
I had a title tarnslator field before. Now I want to add a company translated field.
My i18n table is translation.
My model is Speaker.
Here is the SQL query to execute:
INSERT INTO translation (locale, model, foreign_key, field)
SELECT locale,model, foreign_key, 'company' FROM translation
WHERE model="Speaker" AND field="title";

Related

Can we retrieve the field names from the models.py based on the column names in table from the database in a django project?

models.py: class Name(models.Model): name=models.TextField(db_column="Name_of_the_persion")
like this i defined the model, so that table 'Name' will be created on the database side, with column name as "Name_of_the_persion".
My requirement is like,I need to insert the new row in the table based on the django model field names instead of columns of tabel.
If any one knows, pls help me.
I tried inserting the data into table, by using psycopg2. But this was work in the case of pgadmin point of view only, that means its takes column names of database, instead of model fileds .

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.

Many-to-Many relationship in Zend 2 Framework

I use the Zend 2 Framework to build my web application. I implemented my database table models by this tutorial: http://framework.zend.com/manual/2.1/en/user-guide/database-and-models.html
I have a many-to-many relationship between two models in my database. To get data from them I googled and found this link: http://mattmccormick.ca/2010/04/24/how-to-easily-create-models-and-table-relationships-in-zend-framework/
The problem is that all the table models extends from Zend_Db_Table_Abstract in the example. I don't know how to get data from the models.
I have a table containing votings, every voting has a unique hash id. Every voting also has tags. Therefore I defined a table tags with all the tags available and a voting_tag_map where all many-to-many relationships are mapped.
What I have tried so far is the following, that's code from my VotingTable class:
public function getTagsByVoting($votingHash){
$select = $this->tableGateway->getSql()->select();
$select->from(array('v' => 'voting'))
->join('voting_tag_map', 'v.voting_id=voting_tag_map.voting_id')
->join('tags', 'voting_tag_map.tag_id=tags.tag_id');
$resultSet = $this->tableGateway->selectWith($select);
return $resultSet;
}
It says then:
Since this object was created with a table and/or schema in the constructor, it is read only.
Thats because of the from() method. If I delete the from() method, it says:
Statement could not be executed
Can anyone help me please?
Since this object was created with a table and/or schema in the constructor, it is read only.
This error is because you are trying to set the table name in the from clause, but it's already been set in the contructor of the TableGateway, and you can't change it once set.
If you really need to do this then you can extens AbstractTableGateway yourself then you won't have to add a string tablename to the contructor, but you don't really need to use an alias on your main table...
The SQL error you get when you comment out the from() method will be due to your referencing the votes table as it's alias 'v' in your join, when you are not using the alias v, try changing it to 'voting.XXX' from 'v.XXX'

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.

Trying to find name of TFS DB Table containing custom field data

I have a quick question, what is the name of the TFS 2010 database table that contains values for any custom fields.
I did a query against the TFS_Warehouse DB and the dbo.DimWorkItem table. However, I cannot find any of my custom work item fields under this table.
Can someone point me to the correct TFS 2010 table containing the custom field data? When I worked with Quality Center, the tables were pretty well defined so it was easy to do backend DB queries. TFS does not seem that intuitive.
Thanks
you have to add "reportable" to field definition.
Example - FIELD name="Scope" refname="xxx.Scope" type="String" reportable="dimension"
Wait few minutes and you'll see field in warehouse DB
look,
you need to go to your collection database, and to check a table called something like Fields.
there, you will find the new field properties and the type as well.
you can change the type to string and to be reportable.
go to the table of the WORKITEMLATEST, and check the field- you can see the name of the field like what was mentioned in the FIELDS table,.
open your work item normally, edit that field information, click save...
you can see your data updated in the WORKITEMLATEST table
BUT...
the problem is the STRING type is limited... I tried to add more text.. it keep telling me that number of character is over limit !

Resources