I have e functional Symfony Project. I need to add a Many-To-Many relationships in the project.
I have jobs table and cities table. How can I add this relantionships using Generator (I dont want to alter existing data)?
I will use this relationship in Jobs forms (add,edit,list) to assign multiple Cities to a Job.
You will need a cross reference table sitting between your Jobs and Cities:
<table name="job_city" isCrossRef="true">
<column name="job_id" type="INTEGER" primaryKey="true" />
<column name="city_id" type="INTEGER" primaryKey="true" />
<foreign-key foreignTable="job">
<reference local="job_id" foreign="id" />
</foreign-key>
<foreign-key foreignTable="city">
<reference local="city_id" foreign="id" />
</foreign-key>
</table>
After regenerating you will have a new set of classes: JobCity, JobCityQuery, and JobCityPeer to use. You can add a new job to a city like so:
$job = new Job();
// add job info ...
$job->save();
$city = CityQuery::create()->findOneByName("Austin");
$city->addJob($job);
$city->getJobs(); // returns PropelObjectCollection of Job objects
Related
I have a page where users register and can make their personal diet plan etc.
I am trying to make some graphs with built-in VS dashboards.
I am using VS 2015 and SQL Server Management Studio 15.0.18206.0 if that matters.
My problems are the following:
Automatic (SUM)
Dashboard values default to SUM function, which I am not able to change, as you see in the first picture, but I kind of managed to solve this problem with the help of SQL (SELECT DISTINCT, SELECT TOP(1) etc.)
Automatic (SUM)
Default year count
When I am trying to make a dashboard to show track of user's vitals and activity, which is the core of my statistics, time defaults to YEAR and the result end up like the second picture.
Default year count
There is nothing I can do to change these and I just made irrelevant graphs to fill the page, but it's a shame because I planned to make a lot of graphs with the table you see in the third picture.
User History table
If it helps, the XML code generated from the last dashboard is this:
<?xml version="1.0" encoding="utf-8"?>
<Dashboard>
<Title Text="YearDashBoard" />
<DataSources>
<SqlDataSource ComponentName="DataSource1">
<Name>UserHistory1</Name>
<Connection Name="foodConnectionString" FromAppConfig="true" />
<Query Type="SelectQuery" Name="UserHistory1" Distinct="true">
<Tables>
<Table Name="UserHistory" />
</Tables>
<Columns>
<Column Table="UserHistory" Name="CaloriesDate" />
<Column Table="UserHistory" Name="DailyCalories" />
<Column Table="UserHistory" Name="UserID" />
</Columns>
<Filter>[UserHistory.UserID] = 17</Filter>
</Query>
<ConnectionOptions CloseConnection="true" CommandTimeout="0" />
</SqlDataSource>
</DataSources>
<Items>
<Chart ComponentName="chartDashboardItem1" Name="Chart 1" DataSource="DataSource1" DataMember="UserHistory1">
<DataItems>
<Measure DataMember="DailyCalories" DefaultId="DataItem0" />
<Dimension DataMember="CaloriesDate" DefaultId="DataItem1" />
</DataItems>
<Arguments>
<Argument DefaultId="DataItem1" />
</Arguments>
<Panes>
<Pane Name="Pane 1">
<Series>
<Simple>
<Value DefaultId="DataItem0" />
</Simple>
</Series>
</Pane>
</Panes>
</Chart>
</Items>
<LayoutTree>
<LayoutGroup Weight="100">
<LayoutItem DashboardItem="chartDashboardItem1" Weight="100" />
</LayoutGroup>
</LayoutTree>
</Dashboard>
Finally, with the help of DevExpress technical team, I found out that the whole time there was an invisible scroll bar, but you had to mouse over it (!) while being on the "BINDING" tab of the menu.
i was wondering if any of You can help me with my problem. I'm storing some rasters in Postgis database. Each raster is in its own table and besides 'rid' and 'rast' columns, I manualy added other columns to store raster attributes such as 'metadata'...
I have successfully imported rasters in geoserver using ImageMosaic JDBC and in Layers Preview (OpenLayers) I can see rasters and use getFeatureInfo function, but the problem is that function getFeatureInfo returns table with correct pixel value , 'rid' field is empty (only table header apears) and no other attribute is shown (not even attribute header in table). I'm using default geoserver method for layer preview function.
mapping.postgis.xml.inc file
<!-- possible values: universal,postgis,db2,mysql,oracle -->
<spatialExtension name="pgraster"/>
<mapping>
<masterTable name="mosaic" >
<coverageNameAttribute name="name"/>
<maxXAttribute name="maxx"/>
<maxYAttribute name="maxy"/>
<minXAttribute name="minx"/>
<minYAttribute name="miny"/>
<resXAttribute name="resx"/>
<resYAttribute name="resy"/>
<tileTableNameAtribute name="tiletable" />
</masterTable>
<tileTable>
<blobAttributeName name="rast" />
<keyAttributeName name="rid" />
<textAttributeName name="metadata" />
</tileTable>
</mapping>
connect.postgis.xml.inc
<connect>
<!-- value DBCP or JNDI -->
<dstype value="DBCP"/>
<!-- <jndiReferenceName value=""/> -->
<username value="postgres" />
<password value="postgres" />
<jdbcUrl value="jdbc:postgresql://localhost:5432/web_kartografija" />
<driverClassName value="org.postgresql.Driver"/>
<maxActive value="10"/>
<maxIdle value="0"/>
</connect>
layer.postgis.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE ImageMosaicJDBCConfig [
<!ENTITY mapping PUBLIC "mapping" "mapping.postgis.xml.inc">
<!ENTITY connect PUBLIC "connect" "connect.postgis.xml.inc">]>
<config version="1.0">
<coverageName name="jan"/> <!-- Name of the table in database -->
<coordsys name="EPSG:4326"/>
<!-- interpolation 1 = nearest neighbour, 2 = bilinear, 3 = bicubic -->
<scaleop interpolation="1"/>
<verify cardinality="false"/>
&mapping;
&connect;
</config>
I tried to include <textAttributeName name="metadata" /> as a column name where aditional data is stored, but still no effect. Can anobudy help me with this problem ? Thanks in advance !
I am trying to make a changelog work on two different databases: MS SQL Server and PostgreSQL. The changelog works fine on SQL Server, but the case of the database and fields make it break on PostgreSQL. I have tried not using quotes around the values (which throws an error) and used the objectQuotingStategy="QUOTE_ALL_OBJECTS", both which didn't work.
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet id="create-PushApplication" author="me">
<createTable tableName="PushApplication">
<column name="ApplicationKey" type="NUMERIC(19,0)" autoIncrement="true" remarks="Unique id of the application">
<constraints primaryKey="true" primaryKeyName="PushApplication_PK" nullable="false" />
</column>
<column name="ApplicationId" type="VARCHAR(100)" remarks="Id of the application in the Push Server">
<constraints unique="true" uniqueConstraintName="PushApplication_U1" nullable="false" />
</column>
<column name="MasterSecret" type="VARCHAR(100)" remarks="Password for the application in the Push Server">
<constraints nullable="false" />
</column>
<column name="Name" type="VARCHAR(100)" remarks="Name of the application">
<constraints nullable="false" />
</column>
<column name="Description" type="VARCHAR(200)" remarks="Description of the application" />
<column name="DateCreated" type="DATETIME" remarks="Date the application was created" />
</createTable>
</changeSet>
<changeSet id="create-PushVariant" author="me">
<createTable tableName="PushVariant">
<column name="VariantKey" type="NUMERIC(19,0)" autoIncrement="true" remarks="Unique id of the variant">
<constraints primaryKey="true" primaryKeyName="PushVariant_PK" nullable="false" />
</column>
<column name="VariantId" type="VARCHAR(100)" remarks="Id of the variant in the Push Server">
<constraints unique="true" uniqueConstraintName="PushVariant_UK1" nullable="false" />
</column>
<column name="Secret" type="VARCHAR(100)" remarks="Password for the variant in the Push Server">
<constraints nullable="false" />
</column>
<column name="Name" type="VARCHAR(100)" remarks="Name of the variant">
<constraints nullable="false" />
</column>
<column name="Description" type="VARCHAR(200)" remarks="Description of the variant" />
<column name="ApplicationKey" type="NUMERIC(19,0)" remarks="Id of the application the variant belogns to">
<constraints nullable="false" foreignKeyName="PushVariant_FK1" references="PushApplication(ApplicationKey)" />
</column>
</createTable>
</changeSet>
</databaseChangeLog>
ERROR: relation "pushapplication" does not exist
The table "PushApplication" is created in PostgreSQL but when it tries to create "PushVariant", this error is thrown for the foreign key.
This will work if I change all the database names and column names to lower case. However, this then makes the SQL Server have the incorrect case.
GOAL
The goal is to have "PushVariant" in SQL Server and "pushvariant" in PostgreSQL.
Is there a way that the case in the changelog can remain in SQL Server but have it lower case in PostgreSQL?
Supporting multiple DBMS with a common source code is always about compromises.
Even though there is a SQL standard that clearly defines how non-quoted identifiers have to be stored (all UPPERCASE), the two DBMS you are targeting both ignore this. Postgres stores un-quoted identifiers in lowercase, SQL Server is "case-preserving" (although not always case in-sensitive depending on the collation of the database).
In my personal experience when doing cross DBMS work, (always!) using un-quoted lower case identifiers with underscores is the least problematic way. And if you throw Oracle into the mix at some point in time you wind up all uppercase names.
Having said that: I think Liquibase's quoting strategy actually has a bug. According to the documentation, objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS" should only quote reserved words, so in your example nothing should be quoted. But Liquibase still quotes any name that is using mixed case - this is still the case with the current 3.4.1 version.
I think the best thing was if Liquibase supported the choice objectQuotingStrategy="NEVER" (which it doesn't)
Another option would be to overwrite the default implementation on how the "need" for quoting is detected for Postgres and then use that implementation when running against the Postgres database.
The implementation is actually quite short and would only need to check for non-standard names (starting with a number, containing spaces or other illegal characters) and then quote only those.
I just tried this with the following implementation:
public class NonQuotingPostgresDatabase
extends PostgresDatabase {
#Override
public String correctObjectName(String objectName, Class<? extends DatabaseObject> objectType) {
return quoteIfNecessary(objectName);
}
#Override
public String escapeObjectName(String objectName, Class<? extends DatabaseObject> objectType) {
return quoteIfNecessary(objectName);
}
private String quoteIfNecessary(String objectName) {
if (requiresQuoting(objectName)) {
return "\"" + objectName + "\"";
}
return objectName;
}
protected boolean requiresQuoting(String identifier) {
if (identifier == null) {
return false;
}
if (isQuoted(identifier)) {
return false;
}
return (identifier.contains("-") || startsWithNumeric(identifier) || isReservedWord(identifier));
}
protected boolean isQuoted(String identifier) {
if (identifier == null) {
return false;
}
return (identifier.startsWith("\"") && identifier.endsWith("\""));
}
}
That class essentially leaves quoted identifiers alone and quotes only identifiers that really require it. The big difference to the built-in class is that it doesn't check for mixed case identifiers.
If this is put into a .jar file and the put into the lib subfolder of the Liquibase distribution it will be picked up automatically. All you need to do is add the parameter --databaseClass=NonQuotingPostgresDatabase when running Liquibase against Postgres
Not wanting to clog up the question, I've left out most of the code but I can put it in if it helps.
using Breeze 1.4.9 and Breeze.angular v.0.9.0
I have a simple model: a ChartDefinition has a single DataQuery, and that DataQuery has some parameters.
I have a breeze query:
var query = breeze.EntityQuery
.from("ChartDefinitions")
.expand(["DataQuery","DataQuery.Parameters"]);
//.noTracking();
I can see the server's response (i've replaced most of the simple properties with '...'):
[{"$id":"1","$type":"itaprm4.Domain.ChartDefinition, itaprm4","Id":1,"Title":"FirstChart", ... ,
"DataQuery":
{"$id":"2","$type":"itaprm4.Domain.DataQuery, itaprm4","Id":1, ... ,
"Parameters":
[{"$id":"3","$type":"itaprm4.Domain.DataQueryParameter, itaprm4","Id":1, ...}]
}
}
,{"$id":"4","$type":"itaprm4.Domain.ChartDefinition, itaprm4","Id":2,"Title":"ProjectBudgets", ... ,
"DataQuery":
{"$id":"5","$type":"itaprm4.Domain.DataQuery, itaprm4","Id":2, ... ,
"Parameters":[]
}
},
{"$id":"6","$type":"itaprm4.Domain.ChartDefinition, itaprm4","Id":3,"Title":"ProjectActuals", ... ,
"DataQuery":
{"$id":"7","$type":"itaprm4.Domain.DataQuery, itaprm4","Id":3, ... ,
"Parameters":
[{"$id":"8","$type":"itaprm4.Domain.DataQueryParameter, itaprm4","Id":2,"DataQueryId":3, ...},
{"$id":"9","$type":"itaprm4.Domain.DataQueryParameter, itaprm4","Id":3,"DataQueryId":3, ...}
]
}
}]
After the entities have been materialised though, that last DataQuery object ($id:7) has a parameters array but, it only contains the last parameter ($id:9).
Digging around in breeze.debug I saw that noTracking causes the materialisation code down a different path so tacked the noTracking() option onto the query. This results in both the paramters appearing in the materlised Parameters array. (I'm assuming that since breeze can materialise the object graph correctly, there isn't anything wrong with the code on the server? so I haven't included it in this question...)
I would simply keep the noTracking option on but, I'm registering a constructor function with breeze and it doesn't get called if noTracking is on.
store.registerEntityTypeCtor('ChartDefinition', ChartDefinition);
Is there something else I need to do to get the parameters array filled without the noTracking option?
Edit:
Another observation : without the noTracking option, the DataQueryParameter with $id:8 actually ends up in the parameters array of the DataQuery with $id:5
Turns out this had a lot to do with what was on the server!
Our nHibernate set-up was using a different name for the DataQueryId property on the DataQuery class (the devs in the team tell me there were some issues with updating entities and doing this solved that issue):
<class name="DataQuery" table="sys_DataQuery" dynamic-update="true" >
<id name="Id" column="DataQueryId" type="int" unsaved-value="0">
<generator class="identity" />
</id>
...
<bag name="Parameters" cascade="all-delete-orphan">
<key column="DataQueryId"/>
<one-to-many class="DataQueryParameter"/>
</bag>
</class>
<class name="DataQueryParameter" table="sys_DataQueryParameter" dynamic-update="true" >
...
<property name="DataQueryId" type="int" not-null="true" insert="true" update="true" />
...
</class>
With matching identifiers in the class definitions.
Changing the Id to DataQueryId solved my problem:
<class name="DataQuery" table="sys_DataQuery" dynamic-update="true" >
<id name="DataQueryId" column="DataQueryId" type="int" unsaved-value="0">
<generator class="identity" />
</id>
...
This seems to make sense; how would breeze know to match DataQueryParamter.DataQueryId to DataQuery.Id but, I have no idea why Breeze could correctly materialise the object graph with noTracking switched on though?
I want to use a pie chart per group in Jasper iReport, but I don't know how to create a dataset per group.
Assume I have a table as follows:
Table users
---------
category - user - status
Then I have a the following SQL
select * from users order by category
My display has a simple group band of category with detail showing each user and their status. Ideally I would have each category group header show a pie chart with all the distinct statuses and their counts within that group. I'm at a loss as how to do this in iReport.
If I knew all the categories ahead of time I could just create a dataset for each one using the following:
select status, count(user) from user where category = <current category> group by status
I'm attempting to do this using a JRMapCollectionDataSource that resets each group and pulls the data from the rows in the group using a variable, but I'm not very familiar with the whole reset group and increment paradigm.
Any help?
You can solve this issue without programming following this steps:
sort data by category field and by user field (add sorting via iReport or adding ORDER BY clause to the query in case having deal with jdbc datasource);
add two groups: the 1st group - for category field and the 2nd group - for user field (via iReport). Note: It is not necessarily to add GROUP BY clause to the query;
add Pie Chart component to the Group Header band for the category field;
set evaluationTime and evaluationGroup properties for this pieChart.
Here is working sample for demonstrating how to build Pie Chart. In this sample I've used the csv file as datasource.
The chart shows the quantity of users for every category. I used variable usersCount for counting users in every group, but it is was possible to use built-in variable $V{userGroup_COUNT}.
Here is my jrxml file:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ...>
<field name="category" class="java.lang.Integer"/>
<field name="user" class="java.lang.String"/>
<field name="status" class="java.lang.String"/>
<sortField name="category"/>
<sortField name="user"/>
<variable name="usersCount" class="java.lang.Integer" resetType="Group" resetGroup="userGroup" calculation="Count">
<variableExpression><![CDATA[$F{user}]]></variableExpression>
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
<group name="categoryGroup">
<groupExpression><![CDATA[$F{category}]]></groupExpression>
<groupHeader>
<band height="135">
<pieChart>
<chart evaluationTime="Group" evaluationGroup="categoryGroup">
<reportElement x="158" y="0" width="200" height="135"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<pieDataset>
<dataset resetType="Group" resetGroup="categoryGroup" incrementType="Group" incrementGroup="userGroup"/>
<keyExpression><![CDATA[$F{user}]]></keyExpression>
<valueExpression><![CDATA[$V{usersCount}]]></valueExpression>
<labelExpression><![CDATA[String.valueOf($V{usersCount})]]></labelExpression>
</pieDataset>
<piePlot>
<plot/>
<itemLabel/>
</piePlot>
</pieChart>
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA["Category: " + $F{category}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
</group>
<group name="userGroup">
<groupExpression><![CDATA[$F{user}]]></groupExpression>
</group>
<title>
<band height="79" splitType="Stretch"/>
</title>
</jasperReport>
Here is my csv file (data file - datasource):
category,user,status
1,user1,WORK
1,user1,HOLIDAY
1,user2,SICK
2,user1,WORK
2,user2,WORK
2,user2,HOLIDAY
2,user3,HOLIDAY
2,user4,SICK
3,user1,HOLIDAY
3,user3,HOLIDAY
3,user5,HOLIDAY
4,user1,WORK
4,user1,HOLIDAY
4,user2,SICK
4,user2,WORK
4,user2,SICK
4,user3,HOLIDAY
4,user4,HOLIDAY
4,user5,HOLIDAY
The result will be (via iReport preview):