I have two related entities as follows:
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkOrders" table="app-name-here.rmtk_orders">
<indexes>
<index name="incoterms_id" columns="incoterms_id"/>
<index name="slots_id" columns="slots_id"/>
<index name="statuses_id" columns="statuses_id"/>
<index name="restaurant_users_id" columns="supplier_users_id"/>
<index name="origins_id" columns="origins_id"/>
<index name="payment_code" columns="payment_code"/>
<index name="currencies_iso_code" columns="currencies_iso_code"/>
<index name="domains_id" columns="domains_id"/>
<index name="dispatch_countries_iso_code_2" columns="dispatch_countries_iso_code_2"/>
<index name="subpayment_code" columns="subpayment_code"/>
<index name="language_code" columns="language_code"/>
<index name="users_id" columns="users_id"/>
</indexes>
<unique-constraints>
<unique-constraint name="orders_id2" columns="orders_id2,supplier_users_id,splitter"/>
</unique-constraints>
<id name="ordersId" type="integer" column="orders_id">
<generator strategy="IDENTITY"/>
</id>
<field name="ordersId2" type="string" column="orders_id2" length="36" nullable="true">
<options>
<option name="fixed"/>
</options>
</field>
<field name="username" type="string" column="username" length="256" nullable="false">
<options>
<option name="fixed"/>
</options>
</field>
<field name="createdTs" type="datetime" column="created_ts" nullable="false"/>
<field name="lastUpdate" type="datetime" column="last_update" nullable="true">
<options>
<option name="default">CURRENT_TIMESTAMP</option>
</options>
</field>
<field name="purchasedTs" type="datetime" column="purchased_ts" nullable="false"/>
<field name="remoteAddr" type="string" column="remote_addr" length="45" nullable="true">
<options>
<option name="fixed"/>
</options>
</field>
<field name="comments" type="text" column="comments" length="65535" nullable="true">
<options>
<option name="fixed"/>
</options>
</field>
<field name="channel" type="string" column="channel" length="16" nullable="true">
<options>
<option name="fixed"/>
</options>
</field>
<field name="hidden" type="boolean" column="hidden" nullable="false">
<options>
<option name="default">0</option>
</options>
</field>
<field name="version" type="string" column="version" length="3" nullable="true">
<options>
<option name="fixed">1</option>
</options>
</field>
<field name="userAgent" type="string" column="user_agent" length="256" nullable="true">
<options>
<option name="fixed"/>
</options>
</field>
<field name="backend" type="string" column="backend" length="32" nullable="true">
<options>
<option name="fixed"/>
</options>
</field>
<field name="referralCode" type="string" column="referral_code" length="6" nullable="true">
<options>
<option name="fixed"/>
</options>
</field>
<field name="hasSettlementsAttributed" type="boolean" column="has_settlements_attributed" nullable="false">
<options>
<option name="default">0</option>
</options>
</field>
<field name="totalVerified" type="boolean" column="total_verified" nullable="true"/>
<field name="totalVerificationTs" type="datetime" column="total_verification_ts" nullable="true"/>
<field name="nonViesTaxId" type="string" column="non_vies_tax_id" length="32" nullable="true">
<options>
<option name="fixed"/>
</options>
</field>
<field name="vatNumber" type="string" column="vat_number" length="16" nullable="true">
<options>
<option name="fixed"/>
</options>
</field>
<field name="vatNumberAppliedFromScVatTaxReport" type="boolean"
column="vat_number_applied_from_sc_vat_tax_report" nullable="false">
<options>
<option name="default">0</option>
</options>
</field>
<field name="vatNumberAppliedFromVidr" type="boolean" column="vat_number_applied_from_vidr" nullable="false">
<options>
<option name="default">0</option>
</options>
</field>
<field name="vatNumberViesValidity" type="boolean" column="vat_number_vies_validity" nullable="true"/>
<field name="vatNumberViesValidityVerificationTs" type="datetime"
column="vat_number_vies_validity_verification_ts" nullable="true"/>
<field name="exposedViaApi" type="boolean" column="exposed_via_api" nullable="false">
<options>
<option name="default">0</option>
</options>
</field>
<field name="acknowledged" type="boolean" column="acknowledged" nullable="false">
<options>
<option name="default">0</option>
</options>
</field>
<field name="notifyFailedAmazonInvoiceUploads" type="boolean" column="notify_failed_amazon_invoice_uploads"
nullable="false">
<options>
<option name="default">0</option>
</options>
</field>
<field name="dispatchCountriesIsoCode2AppliedFromScVatTaxReport" type="boolean"
column="dispatch_countries_iso_code_2_applied_from_sc_vat_tax_report" nullable="false">
<options>
<option name="default">0</option>
</options>
</field>
<field name="dispatchCountriesIsoCode2AppliedFromVidr" type="boolean"
column="dispatch_countries_iso_code_2_applied_from_vidr" nullable="false">
<options>
<option name="default">0</option>
</options>
</field>
<field name="magentoEntityId" type="integer" column="magento_entity_id" nullable="true">
<options>
<option name="unsigned"/>
</options>
</field>
<field name="onbuyInternalReference" type="integer" column="onbuy_internal_reference" nullable="true">
<options>
<option name="unsigned"/>
</options>
</field>
<field name="invoiceUploadedSpApi" type="boolean" column="invoice_uploaded_sp_api" nullable="false">
<options>
<option name="default">0</option>
</options>
</field>
<field name="kauflandUploaded" type="integer" column="kaufland_uploaded" nullable="true">
<options>
<option name="unsigned"/>
</options>
</field>
<field name="piiPurged" type="boolean" column="pii_purged" nullable="false">
<options>
<option name="default">0</option>
</options>
</field>
<field name="billingYear" type="smallint" column="billing_year" nullable="true">
<options>
<option name="unsigned"/>
</options>
</field>
<field name="billingMonth" type="boolean" column="billing_month" nullable="true"/>
<field name="splitter" type="integer" column="splitter" nullable="false">
<options>
<option name="default">1</option>
</options>
</field>
<field name="dontInvoice" type="boolean" column="dont_invoice" nullable="false">
<options>
<option name="default">0</option>
</options>
</field>
<field name="kauflandIdOrderUnit" type="string" column="kaufland_id_order_unit" length="32" nullable="true">
<options>
<option name="default">0</option>
</options>
</field>
<many-to-one field="dispatchCountriesIsoCode2" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkCountries"
fetch="LAZY">
<join-columns>
<join-column name="dispatch_countries_iso_code_2" referenced-column-name="countries_iso_code_2"
nullable="true"/>
</join-columns>
</many-to-one>
<many-to-one field="currenciesIsoCode" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkCurrencies"
fetch="LAZY">
<join-columns>
<join-column name="currencies_iso_code" referenced-column-name="currencies_iso_code"/>
</join-columns>
</many-to-one>
<many-to-one field="languageCode" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkLanguages2"
fetch="LAZY">
<join-columns>
<join-column name="language_code" referenced-column-name="language_code"/>
</join-columns>
</many-to-one>
<many-to-one field="users" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkUsers" fetch="LAZY">
<join-columns>
<join-column name="users_id" referenced-column-name="users_id"/>
</join-columns>
</many-to-one>
<many-to-one field="slots" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkSlots" fetch="LAZY">
<join-columns>
<join-column name="slots_id" referenced-column-name="slots_id" nullable="true"/>
</join-columns>
</many-to-one>
<many-to-one field="incoterms" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkIncoterms" fetch="LAZY">
<join-columns>
<join-column name="incoterms_id" referenced-column-name="incoterms_id"/>
</join-columns>
</many-to-one>
<many-to-one field="supplierUsers" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkUsers" fetch="LAZY">
<join-columns>
<join-column name="supplier_users_id" referenced-column-name="users_id"/>
</join-columns>
</many-to-one>
<many-to-one field="paymentCode" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkPaymentMethods"
fetch="LAZY">
<join-columns>
<join-column name="payment_code" referenced-column-name="payment_code"/>
</join-columns>
</many-to-one>
<many-to-one field="origins" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkOrdersOrigins" fetch="LAZY">
<join-columns>
<join-column name="origins_id" referenced-column-name="origins_id"/>
</join-columns>
</many-to-one>
<many-to-one field="domains" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkDomains" fetch="LAZY">
<join-columns>
<join-column name="domains_id" referenced-column-name="domains_id"/>
</join-columns>
</many-to-one>
<many-to-one field="statuses" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkStatuses" fetch="LAZY">
<join-columns>
<join-column name="statuses_id" referenced-column-name="statuses_id"/>
</join-columns>
</many-to-one>
<many-to-one field="subpaymentCode" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkSubpaymentMethods"
fetch="LAZY">
<join-columns>
<join-column name="subpayment_code" referenced-column-name="subpayment_code"/>
</join-columns>
</many-to-one>
<many-to-many field="invoice" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkInvoices" fetch="LAZY">
<join-table name="app-name-here.rmtk_invoices">
<join-columns>
<join-column name="orders_id" referenced-column-name="orders_id"/>
</join-columns>
<inverse-join-columns>
<join-column name="invoices_id" referenced-column-name="invoices_id"/>
</inverse-join-columns>
</join-table>
</many-to-many>
<many-to-many field="addresses" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkAddresses" fetch="LAZY">
<join-table name="app-name-here.rmtk_addresses">
<join-columns>
<join-column name="orders_id" referenced-column-name="orders_id"/>
</join-columns>
<inverse-join-columns>
<join-column name="addresses_id" referenced-column-name="addresses_id" />
</inverse-join-columns>
</join-table>
<cascade>
<cascade-all/>
</cascade>
</many-to-many>
<many-to-many field="tangibleItems" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkOrdersProducts"
fetch="LAZY">
<join-table name="app-name-here.rmtk_orders_products">
<join-columns>
<join-column name="orders_id" referenced-column-name="orders_id"/>
</join-columns>
<inverse-join-columns>
<join-column name="orders_products_id" referenced-column-name="orders_products_id"/>
</inverse-join-columns>
</join-table>
<cascade>
<cascade-all/>
</cascade>
</many-to-many>
<many-to-many field="nonTangibleItems"
target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkOrdersNontangibles" fetch="LAZY">
<join-table name="app-name-here.rmtk_orders_nontangibles">
<join-columns>
<join-column name="orders_id" referenced-column-name="orders_id"/>
</join-columns>
<inverse-join-columns>
<join-column name="on_id" referenced-column-name="on_id" unique="true"/>
</inverse-join-columns>
</join-table>
<cascade>
<cascade-all/>
</cascade>
</many-to-many>
<many-to-many field="mwsMfnRecords" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkAmazonOrdersMfn"
fetch="LAZY">
<join-table name="app-name-here.rmtk_amazon_orders_mfn">
<join-columns>
<join-column name="order_id" referenced-column-name="orders_id2"/>
</join-columns>
<inverse-join-columns>
<join-column name="id" referenced-column-name="id"/>
</inverse-join-columns>
</join-table>
</many-to-many>
<many-to-many field="mwsAfnRecords" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkAmazonOrdersAfn"
fetch="LAZY">
<join-table name="app-name-here.rmtk_amazon_orders_afn">
<join-columns>
<join-column name="amazon_order_id" referenced-column-name="orders_id2"/>
</join-columns>
<inverse-join-columns>
<join-column name="id" referenced-column-name="id"/>
</inverse-join-columns>
</join-table>
</many-to-many>
<many-to-many field="spApiAfnRecords"
target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkAmazonSpApiOrdersAfn" fetch="LAZY">
<join-table name="app-name-here.rmtk_amazon_sp_api_orders_afn">
<join-columns>
<join-column name="amazon_order_id" referenced-column-name="orders_id2"/>
</join-columns>
<inverse-join-columns>
<join-column name="id" referenced-column-name="id"/>
</inverse-join-columns>
</join-table>
</many-to-many>
<many-to-many field="vidrRecords" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkAmazonSpApiVidr"
fetch="LAZY">
<join-table name="app-name-here.rmtk_amazon_sp_api_vidr">
<join-columns>
<join-column name="order_id" referenced-column-name="orders_id2"/>
</join-columns>
<inverse-join-columns>
<join-column name="vidr_id" referenced-column-name="vidr_id"/>
</inverse-join-columns>
</join-table>
</many-to-many>
<many-to-many field="scVatTaxReports"
target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkAmazonSpApiScVatTaxReports" fetch="LAZY">
<join-table name="app-name-here.rmtk_amazon_sp_api_sc_vat_tax_reports">
<join-columns>
<join-column name="order_id" referenced-column-name="orders_id2"/>
</join-columns>
<inverse-join-columns>
<join-column name="sc_id" referenced-column-name="sc_id"/>
</inverse-join-columns>
</join-table>
</many-to-many>
</entity>
</doctrine-mapping>
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkOrdersNontangibles"
table="app-name-here.rmtk_orders_nontangibles">
<indexes>
<index name="settlement_id" columns="settlement_id"/>
<index name="orders_id" columns="orders_id"/>
</indexes>
<unique-constraints>
<unique-constraint name="idx_key_id" columns="orders_id,nontangibles_key,nontangibles_subkey"/>
</unique-constraints>
<id name="onId" type="integer" column="on_id">
<generator strategy="IDENTITY"/>
</id>
<field name="nontangiblesKey" type="string" column="nontangibles_key" length="64" nullable="true">
<options>
<option name="fixed"/>
</options>
</field>
<field name="nontangiblesSubkey" type="string" column="nontangibles_subkey" length="64" nullable="true">
<options>
<option name="fixed"/>
</options>
</field>
<field name="nontangiblesPrice" type="decimal" column="nontangibles_price" precision="15" scale="4"
nullable="false"/>
<field name="nontangiblesTaxRate" type="decimal" column="nontangibles_tax_rate" precision="7" scale="4"
nullable="true"/>
<field name="nontangiblesTaxClass" type="integer" column="nontangibles_tax_class" nullable="true">
<options>
<option name="unsigned"/>
</options>
</field>
<field name="nontangiblesQuantity" type="decimal" column="nontangibles_quantity" precision="15" scale="4"
nullable="false">
<options>
<option name="default">1.0000</option>
</options>
</field>
<field name="issuedcreditnote" type="boolean" column="issuedCreditNote" nullable="false">
<options>
<option name="default">0</option>
</options>
</field>
<field name="isfromamazonsettlement" type="boolean" column="isFromAmazonSettlement" nullable="false">
<options>
<option name="default">0</option>
</options>
</field>
<field name="ebayReferenceId" type="integer" column="ebay_reference_id" nullable="true">
<options>
<option name="unsigned"/>
</options>
</field>
<many-to-one field="orders" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkOrders" fetch="LAZY">
<join-columns>
<join-column name="orders_id" referenced-column-name="orders_id"/>
</join-columns>
</many-to-one>
<many-to-one field="settlement" target-entity="ISV-Here\App-Name-Here\Doctrine\Entities\RmtkAmazonSettlements"
fetch="LAZY">
<join-columns>
<join-column name="settlement_id" referenced-column-name="settlement_id"/>
</join-columns>
</many-to-one>
</entity>
</doctrine-mapping>
The end goal is to clone an instance of ISV-Here\App-Name-Here\Doctrine\Entities\RmtkOrders along with its associations. I have implemented __clone() as follows:
class Orders
{
.....
public function __clone()
{
if ($this->ordersId) {
unset($this->ordersId);
$nonTangibleItems = new ArrayCollection();
foreach ($this->nonTangibleItems as $nonTangibleItem) {
$nonTangibleItemClone = clone $nonTangibleItem;
$nonTangibleItemClone->setOrder($this);
$nonTangibleItems->add($nonTangibleItemClone);
}
$this->nonTangibleItems = $nonTangibleItems;
}
}
}
}
My controller is as follows:
/**
* #var RmtkOrders $rmtkOrder
*/
$rmtkOrder = $this->entityManager->find(DOCTRINE_ENTITIES_NAMESPACE . 'RmtkOrders', 123456);
$rmtkOrder->setOrdersId2('das' . time());
$rmtkOrder->setInvoice(null);
$rmtkOrder->setTangibleItems(new ArrayCollection());
$rmtkOrder->setVidrRecords(new ArrayCollection());
$rmtkOrder->setAddresses(new ArrayCollection());
$rmtkOrder->setScVatTaxReports(new ArrayCollection());
$rmtkOrder->setSpApiAfnRecords(new ArrayCollection());
$copy = clone $rmtkOrder;
$this->getEntityManager()->persist($copy);
try {
$this->getEntityManager()->flush($copy);
} catch (Exception $ex) {
Cli::doOutputLine($ex->getMessage());
}
The MariaDB general log shows the following INSERT statements:
2506366 Query INSERT INTO app-name-here.rmtk_orders (orders_id2, username, created_ts, last_update, purchased_ts, remote_addr, comments, channel, hidden, version, user_agent, backend, referral_code, has_settlements_attributed, total_verified, total_verification_ts, non_vies_tax_id, vat_number, vat_number_applied_from_sc_vat_tax_report, vat_number_applied_from_vidr, vat_number_vies_validity, vat_number_vies_validity_verification_ts, exposed_via_api, acknowledged, notify_failed_amazon_invoice_uploads, dispatch_countries_iso_code_2_applied_from_sc_vat_tax_report, dispatch_countries_iso_code_2_applied_from_vidr, magento_entity_id, onbuy_internal_reference, invoice_uploaded_sp_api, kaufland_uploaded, pii_purged, billing_year, billing_month, splitter, dont_invoice, kaufland_id_order_unit, dispatch_countries_iso_code_2, currencies_iso_code, language_code, users_id, slots_id, incoterms_id, supplier_users_id, payment_code, origins_id, domains_id, statuses_id, subpayment_code) VALUES ('das1674928808', 'email-address-here#example.com', '2023-01-28 19:16:48', '2023-01-25 03:22:06', '2023-01-24 00:54:39', NULL, NULL, 'AFN', 0, NULL, NULL, NULL, NULL, 0, 1, '2023-01-28 19:16:50', NULL, '', 1, 0, NULL, NULL, 1, 0, 0, 1, 0, NULL, NULL, 0, NULL, 0, NULL, NULL, 1, 0, NULL, 'FR', 'EUR', 'fr_FR', 260636, 744311, NULL, 55999, 'amazon', 5, 2, 73, NULL)
2506366 Query INSERT INTO app-name-here.rmtk_orders_nontangibles (nontangibles_key, nontangibles_subkey, nontangibles_price, nontangibles_tax_rate, nontangibles_tax_class, nontangibles_quantity, issuedCreditNote, isFromAmazonSettlement, ebay_reference_id, orders_id, settlement_id) VALUES ('shipping', NULL, '0', '20', NULL, '1', 0, 0, NULL, 1893942, NULL)
2506366 Query INSERT INTO app-name-here.rmtk_orders_nontangibles (nontangibles_key, nontangibles_subkey, nontangibles_price, nontangibles_tax_rate, nontangibles_tax_class, nontangibles_quantity, issuedCreditNote, isFromAmazonSettlement, ebay_reference_id, orders_id, settlement_id) VALUES ('shipping_discount', NULL, '0', '20', NULL, '1', 0, 0, NULL, 1893942, NULL)
2506366 Query INSERT INTO app-name-here.rmtk_orders_nontangibles (nontangibles_key, nontangibles_subkey, nontangibles_price, nontangibles_tax_rate, nontangibles_tax_class, nontangibles_quantity, issuedCreditNote, isFromAmazonSettlement, ebay_reference_id, orders_id, settlement_id) VALUES ('promotion_discount', NULL, '0', '20', NULL, '1', 0, 0, NULL, 1893942, NULL)
2506366 Query INSERT INTO app-name-here.rmtk_orders_nontangibles (orders_id, on_id) VALUES (1893942, 1091050)
The very last INSERT statement leads to An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1091053' for key 'PRIMARY'. All the rest of the INSERT statements are exactly as desired.
The very last INSERT statement should not be there at all. Could you spot what the problem is and why this last INSERT statement is executed?
Did you try after clone to detach from the entity manager your new instance ?
$this->getEntityManager()->detach($copy);
I'm not sure to understand your problem, because it sounds like code works (and fails) exactly as expected. As you are cloning RmtkOrders, this is a new entity that doctrine have to persist.
When an object is cloned, a new one is setup with the same properties. So, it fails because the initial entity already has an id and the cloned one duplicate this id. This id violates the unique integrity constraints of primary key when Doctrine try to store it.
In my opinion, if you want to create a new entity and store it, you should implement the magic method __clone() to unset RmtkOrders::id
public function __clone()
{
$this->id = null;
}
Now doctrine will autogenerate a new id on persist.
Optionally, if needed, you perhaps have to clone the subentity in the same way.
public function __clone()
{
$this->id = null;
//the below code is necessary because __construct is NOT called by __clone
$this->setInvoice(null);
$this->setTangibleItems(new ArrayCollection());
$this->setVidrRecords(new ArrayCollection());
$this->setAddresses(new ArrayCollection());
$this->setScVatTaxReports(new ArrayCollection());
$this->setSpApiAfnRecords(new ArrayCollection());
}
and your controller becomes:
/**
* #var RmtkOrders $rmtkOrder
*/
$rmtkOrder = $this->entityManager->find(DOCTRINE_ENTITIES_NAMESPACE . 'RmtkOrders', 123456);
$copy = clone $rmtkOrder;
$copy->setOrdersId2('das' . time()); //I don't understand this line, it could be move to __clone method
$this->getEntityManager()->persist($copy);
try {
$this->getEntityManager()->flush($copy);
} catch (Exception $ex) {
Cli::doOutputLine($ex->getMessage());
}
In any case, I strongly advice you to never update $rmtkOrder, but only manipulate the cloned $clone. And I suggest you to use Model pattern if the magic __clone method is already used for another use case.
I want to load textual data on any member in a natural hierarchy in icCube, but I am not able to display the textual values with MDX for the upper-levels.
Consider the following (natural) hierarchy, data and expected outcome:
(It might look a bit weird, but icCube allows to have the leaf empty for SUB013 and SUB014.)
As you can see in the desired outcome in the picture above, I expect "voila" to be displayed on SUB015.
But, I can not get it to work. See the outcome I get with MDX:
I have the following issues:
the value is empty (I have used the no aggregation type on text)
another observation is that also the amount is empty for a no aggregation type
Is this solvable, somehow?
(enclosed as a snippet - not runnable - the schema I used, which you can upload in your instance of icCube)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<schemaFactory revisionNumber="77">
<schemaDefinition name="text on sub-total" description="" group="Research" loadOnStartup="false">
<activateIncrementalLoad>false</activateIncrementalLoad>
<useUnknownMembersInFacts>false</useUnknownMembersInFacts>
<autoCleanUpTableColumns>false</autoCleanUpTableColumns>
<useFactPartitioning>false</useFactPartitioning>
<callGarbageCollector>NONE</callGarbageCollector>
<backup>NONE</backup>
<nonEmptyCachePolicy>NONE</nonEmptyCachePolicy>
<nonEmptyCacheType>REGULAR</nonEmptyCacheType>
<nonEmptyCachePersistency>MEMORY</nonEmptyCachePersistency>
<storagePolicy>DEFAULT</storagePolicy>
<hierarchyUniqueNameStyle>IncludeDimensionName</hierarchyUniqueNameStyle>
<inMemoryDS name="manual">
<memoryDataTable tableName="data" rowLimit="-1" id="3c476e37-708d-4066-831c-89508134beb7">
<column name="dim" tableType="STRING" type="STRING" selected="true" primaryKey="false" nullObjectAsString=""/>
<column name="costs" tableType="STRING" type="DOUBLE" selected="true" primaryKey="false" nullObjectAsString=""/>
<column name="text" tableType="STRING" type="STRING" selected="true" primaryKey="false" nullObjectAsString=""/>
<addRowNumber>false</addRowNumber>
<stringDateConverter></stringDateConverter>
<trimStrings>true</trimStrings>
<columnSeparator>\t</columnSeparator>
<commentMarker>#</commentMarker>
<dataAsString>dim costs text
CHILD001
CHILD002
CHILD003 10 hi
CHILD004
CHILD005
SUB013 59 salut
SUB014 69 bonjour
SUB015 180 voila
</dataAsString>
</memoryDataTable>
<memoryDataTable tableName="dim" rowLimit="-1" id="373a4b14-5b7d-441d-91c0-caabeb670936">
<column name="SubTotal" tableType="STRING" type="STRING" selected="true" primaryKey="false" nullObjectAsString=""/>
<column name="Leaf" tableType="STRING" type="STRING" selected="true" primaryKey="false" nullObjectAsString=""/>
<addRowNumber>false</addRowNumber>
<stringDateConverter></stringDateConverter>
<trimStrings>true</trimStrings>
<columnSeparator>\t</columnSeparator>
<commentMarker>#</commentMarker>
<dataAsString>SubTotal Leaf
SUB013
SUB014
SUB015 CHILD001
SUB015 CHILD002
SUB015 CHILD003
SUB015 CHILD004
SUB015 CHILD005
</dataAsString>
</memoryDataTable>
</inMemoryDS>
<multiLevelDimension dataTableId="373a4b14-5b7d-441d-91c0-caabeb670936" isTimeDimension="false" isDefaultTimeDimension="false" isIndexingByRange="false" unknownMemberName="" id="6b08783b-b33c-4499-b253-212753be23fd" name="Dim">
<multiLevelHierarchy hasAllLevel="true" allLevelName="All-L" allMemberName="All-M" name="Dim" isDefault="true" defaultMemberName="">
<factAggregationType>MEMBER_AND_ANCESTORS</factAggregationType>
<level name="subtotal" nameUnique="true" nameUniqueInParent="false" keyUnique="true" ignoreNameCollision="false">
<column name="SubTotal"/>
<nameCol name="SubTotal"/>
<orderType>NONE</orderType>
<orderKind>ASC</orderKind>
</level>
<level name="leaf" nameUnique="true" nameUniqueInParent="false" keyUnique="true" ignoreNameCollision="false">
<column name="Leaf"/>
<nameCol name="Leaf"/>
<orderType>NONE</orderType>
<orderKind>ASC</orderKind>
</level>
</multiLevelHierarchy>
</multiLevelDimension>
<cube id="1c361ef2-ebba-475f-9cc8-83910e4530e2" name="data" description="">
<defaultFacts measureGroupName="Facts" partitioningLevelName="" partitioningType="NONE" newGeneration="true" dataTableId="3c476e37-708d-4066-831c-89508134beb7" aggregateDataSourceFacts="false" unresolvedRowsBehavior="ERROR">
<rowFactAggregationType>ADD_ROW</rowFactAggregationType>
<measure name="costs sum" aggregationType="SUM">
<rollupHierarchy></rollupHierarchy>
<dataColumn name="costs"/>
<cellProperties></cellProperties>
<emptyIsZero>false</emptyIsZero>
</measure>
<measure name="costs max" aggregationType="MAX">
<rollupHierarchy></rollupHierarchy>
<dataColumn name="costs"/>
<cellProperties></cellProperties>
<emptyIsZero>false</emptyIsZero>
</measure>
<measure name="costs no agg" aggregationType="NONE">
<rollupHierarchy></rollupHierarchy>
<dataColumn name="costs"/>
<cellProperties></cellProperties>
<emptyIsZero>false</emptyIsZero>
</measure>
<measure name="text max" aggregationType="MAX">
<rollupHierarchy></rollupHierarchy>
<dataColumn name="text"/>
<cellProperties></cellProperties>
<emptyIsZero>false</emptyIsZero>
</measure>
<measure name="text no agg" aggregationType="NONE">
<rollupHierarchy></rollupHierarchy>
<dataColumn name="text"/>
<cellProperties></cellProperties>
<emptyIsZero>false</emptyIsZero>
</measure>
<links dimensionId="6b08783b-b33c-4499-b253-212753be23fd">
<viewLinks type="ALL_LEVELS">
<toColumns name="dim"/>
</viewLinks>
</links>
</defaultFacts>
</cube>
<localization enabled="false"/>
<script>
<content>
</content>
</script>
</schemaDefinition>
</schemaFactory>
In icCube a node value, even if leaf, can be the result of an aggregation over multiple facts rows. When you specify, NO_AGGREGATION, as aggregation method the NULL is returned if more than one single row is in play.
For you example as SUB015 has a child with value, CHILD003. And the dimension is defined with 'Fact Aggr. Type' as 'Members and Ancestors'.
Two solutions :
1) Add a Dimension member property that is retrieved using a calculated member.
2) Use a dimension with 'Fact Aggr. Type' as 'Members' but you will get wrong cost.
I am trying to convert data from a xml field into a table. I have found multiple solutions on this website, but none of them seem to give me exactly what I need.
The xml looks like this:
<table>
<id>{100}</id>
<rows>
<row>
<columns>
<column name="cur" value="EUR" type="System.String" />
<column name="item" value="Item a" type="System.String" />
<column name="price" value="2.5" type="System.Decimal" />
<column name="qty" value="20" type="System.Int32" />
<column name="Key" value="1" type="System.Int32" />
</columns>
</row>
<row>
<columns>
<column name="cur" value="EUR" type="System.String" />
<column name="item" value="Item b" type="System.String" />
<column name="price" value="30" type="System.Decimal" />
<column name="qty" value="30" type="System.Int32" />
<column name="Key" value="2" type="System.Int32" />
</columns>
</row>
</rows>
<key>Key</key>
</table>
I would like the result to look like this:
id key cur item price qty
100 1 EUR Item a 2.5 20
100 2 EUR Item b 30 30
I hope someone can help me.
Try it like this:
DECLARE #x XML=
'<table>
<id>{100}</id>
<rows>
<row>
<columns>
<column name="cur" value="EUR" type="System.String" />
<column name="item" value="Item a" type="System.String" />
<column name="price" value="2.5" type="System.Decimal" />
<column name="qty" value="20" type="System.Int32" />
<column name="Key" value="1" type="System.Int32" />
</columns>
</row>
<row>
<columns>
<column name="cur" value="EUR" type="System.String" />
<column name="item" value="Item b" type="System.String" />
<column name="price" value="30" type="System.Decimal" />
<column name="qty" value="30" type="System.Int32" />
<column name="Key" value="2" type="System.Int32" />
</columns>
</row>
</rows>
<key>Key</key>
</table>';
SELECT #x.value('(/table/id)[1]','varchar(max)') AS id --are the curly brackets there on purpose?
,Rw.value('(columns/column[#name="Key"]/#value)[1]','int') AS [key]
,Rw.value('(columns/column[#name="cur"]/#value)[1]','varchar(max)') AS cur
,Rw.value('(columns/column[#name="item"]/#value)[1]','varchar(max)') AS item
,Rw.value('(columns/column[#name="price"]/#value)[1]','decimal(10,4)') AS price
,Rw.value('(columns/column[#name="qty"]/#value)[1]','int') AS qty
FROM #x.nodes('/table/rows/row') AS A(Rw)
I have a pretty simple Propel question. I'm storing leads in a database. Those leads have one or more community interests. The tables I'm using are named, 'lead', 'community', and a 'lead_communities' join table. What's the best way to delete all of a lead's community interests?
Here are some more details. The Propel schema looks like this:
<table name="community">
<column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true" />
<column name="name" type="VARCHAR" size="255" />
<column name="address" type="VARCHAR" size="255" />
etc...
<table name="lead_communities">
<column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true"/>
<column name="lead_id" type="INTEGER" />
<column name="community_id" type="INTEGER" />
<column name="created_date" type="DATE" size="4" />
<foreign-key foreignTable="community" refPhpName="Lead_Communities">
<reference local="community_id" foreign="id"/>
</foreign-key>
<foreign-key foreignTable="lead" refPhpName="Lead_Communities">
<reference local="lead_id" foreign="id"/>
</foreign-key>
</table>
<table name="lead">
<column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true"/>
<column name="salutation" type="VARCHAR" size="20" />
<column name="first_name" type="VARCHAR" size="255" defaultValue="" />
<column name="last_name" type="VARCHAR" size="255" defaultValue="" />
<column name="email" type="VARCHAR" size="255" defaultValue="" />
etc..
Here's how I select the lead from the database:
$lead = LeadQuery::create()->filterByEmail($enauk)->findOne();
So, what I hope to do is something like:
$lead->deleteLeadCommunities();
Well, the easiest way I can think of without any other context is simply doing a query on the join table with a delete() call:
$numDeleted = LeadCommunitiesQuery::create()
->filterByLead($lead)
->delete();
Just to be clear, there is no generated method like what you want (deleteLeadCommunities), but you could always write it for convenience, and replace $lead in my example code with $this. So inside Lead.php:
public function deleteLeadCommunities() {
return LeadCommunitiesQuery::create()
->filterByLead($this)
->delete();
}