Doctrine2 Mapping Problems on a Symfony2 Project - database

I have 2 entities Item and Itemimage. The relationship between Item to Itemimage is OneToMany Unidirectional with JoinColumn. I took help from doctrine documentation. The OneToMany unidirectional with JoinColumn is achieved with the ManyToMany Annotation:
/**
* #ManyToMany(targetEntity="Itemimage")
* #JoinTable(name="itemimage",
* joinColumns={#JoinColumn(name="item_id", referencedColumnName="id")},
* inverseJoinColumns={#JoinColumn(name="image_id", referencedColumnName="itemid")}
* )
*/
Where:
image_id: itemid is a property in the Itemimage Entity
item_id: is the primary key property of the Item Entity
I made a property $images in Item Entity and gave it the above docblock. The problem is that when I tried updating the schema. I get a doctrine error: "The Table 'itemimage' already exists". I'm sure that is not the case. I have no idea what to do.
Please help me with this.
Thanks! I appreciate your help.

It is supposed to be:
/**
* #ManyToMany(targetEntity="Itemimage")
* #JoinTable(name="itemimage_map",
* joinColumns={#JoinColumn(name="item_id", referencedColumnName="id")},
* inverseJoinColumns={#JoinColumn(name="image_id", referencedColumnName="id")}
* )
*/
leading to the creation of a third table (itemimage_map) that will contain just the mapping of the other two tables. It is not an existing table you have to join there. That table will contain item_id and image_id which are the primary keys of tables you want to map.

Related

which view get all information about all data dictionary views?

I need data dictionary view that gets all info about all data dictionary view details in oracle
select * from user_dba;
desc dba_directiories;
It is called dictionary.
Looks like this:
SQL> desc dictionary
Name Null? Type
----------------------------------------- -------- ----------------------------
TABLE_NAME VARCHAR2(30)
COMMENTS VARCHAR2(4000)
You can query it like this (for example, searching for ones that talk about "constraints"):
SQL> select * From dictionary where lower(comments) like '%constraint%';
TABLE_NAME COMMENTS
------------------------- --------------------------------------------------
ALL_CONSTRAINTS Constraint definitions on accessible tables
ALL_CONS_COLUMNS Information about accessible columns in constraint
definitions
USER_CONSTRAINTS Constraint definitions on user's own tables
USER_CONS_COLUMNS Information about accessible columns in constraint
definitions
SQL>
You can use following query on system-supplied DICTIONARY view which contains the names and abbreviated descriptions of all data dictionary views.
SELECT * FROM DICTIONARY ORDER BY 1
It has mainly divided into 3 sets. So the views with
- Prefix DBA_ show all relevant information in the entire database. DBA_ views are intended only for administrators.
- Prefix ALL_ refer to the user's overall perspective of the database. These views return information about schema objects to which the user has access through public or explicit grants of privileges and roles, in addition to schema objects that the user owns.
- Prefix USER_ views most likely to be of interest to typical database users are those with the prefix USER_.

How to apply condition to Laravel eloquent relation

I have a ProcessHistory and Person model I need a eloquent code for relation with multiple condition.
Conditions:
1. oindex = oindex
2. pat_id = pat_id
I want a eloquent code to get result of the following sql code
select * from tbl_process_history as s join tbl_persons as p on (s.oindex = p.oindex and s.pat_id = p.pat_id)
I need to get all the persons having same oindex and pat_id. I have tried with below eloquent code where I can apply condition inside of relation 'own'. Here I can apply only for as static value.
ProcessHistory::with(['own'=>function($query){
return $query->where('pat_id','');
}])->get();
I need a condition inside of relation where I can match pat_id of process history model with persons model.
I just found that I was actually searching for relationship with composite key but this feature is not provided in laravel. It can be solved by using https://github.com/topclaudy/compoships package.
ProcessHistory::with(['own'=>function($query) use ($param){
return $query->where('pat_id',$param);
}])->get();

Cakephp. How do i access other columns of a table if the only referenced column of that table is the id column

i have TableA referencing id column of TableB as foreign key. The code below outputs the id of TableB, so i want to use this id to access the rest of the columns of this entity. How do i do that?
Thi is the index.ctp below
<td><?= $tableA->has('tableB') ? $this->Html->link($tableA->$tableb_id->, ['controller' => 'TableA', 'action' => 'view', $tableA->TableB->id]) : '' ?></td>
CakePHP 3.0 will attach associated tables to each Entity using an underscore singular naming convention (for BelongsTo, and underscore plural for hasMany) when using the contain feature.
So in your controller you would find records like this.
public function index() {
$tableA = $this->TableA->find()->contain('TableB')->first();
$this->set(compact('tableA'));
}
The above will find the first record, and also the associated TableB record. We can see this by using the debug feature.
$tableA = $this->TableA->find()->contain('TableB')->first();
debug($tableA->toArray());
In your view you can access the TableB as a property of $tableA
// will output the association TableB
debug($tableA->table_b_id); // the ID column
debug($tableA->table_b); // all of TableB columns
You should learn the Cake bake features on the command line, as this will add #property annotations to the entity classes for associations.
You can bake TableA like this
$ bin/cake bake model TableA
Which will create src/Model/Entity/TableA.php and src/Model/Table/TableATable.php
For the TableA.php entity it will have a comment block like this.
/**
* #property int id
* // more properties
*
* #property \App\Model\Entity\TableB $table_b
*/
class TableA extends Entity {
// ...
}
As long as you follow Cake's conventions, and use the Bake features. A lot of this can be setup for you. Making it easier to find associated data. These #property features also enable autocomplete features in PhpStorm, Eclipse and other IDEs for PHP.

how to add a parent table value CGridView using yii

Currently my CGridView gives following result.
http://imageshack.us/a/img821/2391/44264318.png
Here City is actually CityID From a parent table. City table has one-to-many relationship with Campus table. I want to show city.cityname instead of city.cityid from parent table. Can someone help please.
Database structure is as
http://imageshack.us/photo/my-images/845/82338990.png/
change that column to
array (
'name'=>'mycol
'value'=>'$data->city->cityname',
);
where city is a relation name, and cityname is an attribute from the linked class.
To sort see this article http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview/
in your grid columns use:
array (
...
'city.cityname',
... other columns...
);

How do I query in GQL using the entity key

How do I write a query against the entity key using GQL in the Google App Engine Data Viewer ?
In the viewer, the first column (Id/Name) displays as name=_1, in the detail view it shows the key as
Decoded entity key: Programme: name=_1
Entity key: agtzcG9...................
This query does not work:
SELECT * FROM Programme where name = '_1'
You can use the entity's key to retrieve it:
SELECT * FROM Programme where __key__ = KEY('agtzcG9...................')
And, you should be able to query using the name similarly:
SELECT * FROM Programme where __key__ = KEY(Programme, '_1')
Note that this is not something that you would want to do in your AppEngine application; as Nick notes in his comment, it is a huge waste of time. Really, this example is only good to show you how to query by Key in the Admin console.
For numeric IDs, a form similar to the query-by-name works:
SELECT * from Programme where __key__ = KEY('Programme', 1234567)
I found this form especially useful in the Admin Console.
You don't need to query to get an entity by key at all - you can simply fetch the entity by its key. In Python, you can do this with MyModel.get_by_key_name('_1'). This is 3 to 5 times faster than Adam's suggestion of using a query.
When querying by key, you need to match the key exactly, including the parent and not just the ID or name. Of course, if the parent is null, as in the example above, the ID or Name and the type of entity is enough.
If you have the already encoded entity key, you can just use that like:
SELECT * FROM Programme where __key__ = KEY('agtzcG9...................')
For the simple example above,
SELECT * FROM Programme where __key__ = KEY('Programme', '_1')
will do, but if your key has a parent, like
Paren: id=123
Then the query would be
SELECT * FROM Programme where __key__ = KEY('Paren', 123, 'Programme', '_1')
If the parent itself has a parent, you need to add that too. For more details see the official GQL documentation.
There does not appear to be a way to select everything with the same ID or name regardless of parent.
Just a quick note on this: When I use any quotes around any of the args in KEY, the call fails (in the admin console I get the error popup).
For example, for type "mytype" with ID/Name 12345, this does NOT work:
SELECT * FROM mytype WHERE __key__ = KEY('mytype', '12345')
But this does:
SELECT * FROM mytype WHERE __key__ = KEY(mytype, 12345)

Resources