Doctrine - using the same table for multiple (many-to-many) relations - symfony

Say I have three entities: Page, Product and Media.
Well, I would like to have this realations:
Page <-(many-to-many)-> Media
Product <-(many-to-many)-> Media
Using the common approach for solving this, it would result two tables that look very similar.
My question is: Can I use a single table for both relations using Doctrine?
What I only need is a way of suggesting a new column that would indicate if the counterpart of media on a particular row is Product or Page.

The answer is No. Relations table N:N must have unique table name.
But... You can aways create a structure of that kind:
Page <--1:N--> MyGreatJoinTable <--N:1--> Media
Product <--1:N--> MyGreatJoinTable <--N:1--> Media
You don't need to describe the reference because it refers to a different table, but if you want you can do it.
Of course MyGreatJoinTable will have at least three columns:
- PageId
- ProductId
- MediaId

Related

Go to different main table from same field AX 2012

I have a InvoiceAccount field in table. And another field in this table is PackingSlipAXType. If PackingSlipAXType is Sales, InvoiceAccount field value is customer account. If type is PurchReturn, InvoiceAccount field value is vendor account.
When value is customer account, when right click and go to main table i want to go Customer
and
When value is vendor account, when right click and go to main table i want to go vendor.
How can i do this in same field?
There are two primary ways. One is code and the other is using native MorphX and Conditional Table Relations. Code gives you more flexibility, but conditional table relations are simpler and "just work".
Conditional Table Relations
Using conditional table relations. I created a new table and AccountNum would represent a customer or vendor account, and the base enum SalesPurch is used to indicate if it is a Customer Account (Sales) or a Vendor Account (Purch). Similar to your setup.
See conditional table relations - https://learn.microsoft.com/en-us/dynamicsax-2012/developer/conditional-table-relations
See here for more info too.
Custom JumpRef & Lookup
You will likely want both a jumpRef and a lookup to both go to the correct main table and lookup the correct values.. This is code, but you have all the flexibility in the world...but may not need it.
Jumpref - https://community.dynamics.com/365/financeandoperations/b/faisalfareedaxlibrary/posts/ax-2012-how-to-use-jumpref-method
Lookup - https://learn.microsoft.com/en-us/dynamicsax-2012/developer/how-to-add-a-lookup-form-to-a-control
Jumpref example at \Data Dictionary\Tables\TmpCostAllocationBase_RU\Methods\jumpRefAgreement
Lookup example at \Data Dictionary\Tables\TmpCostAllocationBase_RU\Methods\lookupAgreement

Report grouped in Axapta 3.0

I need to generate a report that groups by two fields the records of a table in an Axapta 3.0. The source table I have has this structure:
And the report I want to get looks like this:
What sections and properties should the report have in order to create such a design?
Thank you very much.
If you have backing tables for the fields 'LOTE' and 'DIARIO' then the easy option is to use them, the query should look like this, all inner joined:
LoteTable
DiarioTable
YourTable
Remember to set Relations to Yes on the two first tables (or define the relations your self).
If you do not have backing tables, you can create them as views on your table.
The LoteTable view should contain the following fields:
Lote
Proveedor
CountOfRecId (Aggregation Count)
The CountOfRecId field will make the view a group by on the first two fields.

Storing item currencies in SQLite database

I'm building out a schema for a site that will need to store a product's currency. I'm not sure whether I'll be needing to be able to convert from one currency to another, however, I'm presuming that will probably be necessary. My db schema is below. (this is for a mobile app btw). My question is, should I just simplify things by adding an additional column called currency to my item table? Does my design make sense? Thank you.
Edit (based on reply from Victor below): the items have a many-to-many relationship with order table. How about putting the currency id on order table since most likely all items in an order will be in the same currency?
exchange_rates
id
currency_from
currency_to
ex_rate
item_currencies
currency_id
item_id (from items/products table)
currencies
id
code
symbol
The schema looks good but I think that the *item_currencies* table is not necessary.
In your items table you can just add the currency_id column. Keep it together with all the item properties :)

Drupal create views involving LEFT JOIN Sub-Select with non-existent node

i'm using Drupal 6
I have this table relation and I've translated into CCK complete with it's relation.
Basically when I view a Period node, I have tabs to display ALL Faculty nodes combined with Presence Number.
here's the table diagram: http://i.stack.imgur.com/7Y5cU.png
Translated into CCK like these:
CCK Faculty (name),
CCK Period (desc,from,to) and
CCK Presence(node-reference-faculty, node-reference-period, presence_number)
Here's my simple manual SQL query that achieve this result: http://i.stack.imgur.com/oysd3.png
SELECT faculty.name, presence.presence_number FROM Faculty AS faculty
LEFT JOIN (SELECT * FROM Presence WHERE Period_id=1) AS presence ON faculty.id=presence.Faculty_id
The value of 1 for Period_id will be given by the Period Node ID from the url argument.
Now the hardest part, is simulating simple SQL query above into Views. How can I make such query into Views in Drupal-6 or Drupal-7 ?
thanks for any helps.
The main issue, which I think you've noticed, is that if you treat Faculty as the base for your join, then there is no way to join on the Presence nodes. Oppositely, if you treat Presence as the base, then you will not see faculties that have no presence number.
There is no easy way, using your currently defined structure, to do these joins in views.
I would say your easiest option is to remove the 'node-reference-faculty' field from the presence node and add a node-reference-presence field to the faculty. Since CCK fields can have multiple values, you can still have your one-to-many relationship properly.
The one downside of this is that then you need to manage the presence-faculty relationship from the faculty nodes instead of the presence nodes. If that's a show stopper, which it could be depending on your workflow, you could have BOTH node-reference fields, and use a module like http://drupal.org/project/backreference to keep them in sync.
Once you have your reference from faculty -> presence, you will need to add a relationship in Views. Just like adding a field or a filter, open the list of relationships and find the one for your node-reference field.
Next, you will need to add an argument for period id and set it up to use a node id from the url. The key thing is that when you add the argument, it will ask which relationship to use in its options. You will want to tell it to use your newly added presence relationship.
You don't really need to do a subquery in your SQL like that. This should be the same thing and won't make mysql try to create a temporary table. I mention it because you can't really do subqueries in Views unless you are writing a very custom Views handler, but in this case you don't really need the subquery anyway.
Ex.
SELECT f.name, p.presence_number
FROM Faculty AS f
LEFT JOIN Presence AS p ON f.id=p.Faculty_id
WHERE p.Period_id=1;
I wrote an article about how to achieve a similar outcome here. http://scottanderson.com.au/#joining-a-views-query-to-a-derived-table-or-subquery
Basically how to alter a Views query to left join on a sub-query.

How to fetch pretty advanced relation in Drupal 6 - Views 2?

I have three content types: Artist, Artwork, Exhibition. An Exhibition has a field 'artworks' (unlimited values). An Artwork has a field 'artist' (1 value, required).
And there is the relation I can't seem to find with Views: I want all Exhibitions an Artist ever participated in. Which means: on the Artist page, show all Exhibitions all Artworks of this Artist were ever in.
The problem (I think) is that one field (Exhibition.artworks) has many values. Yet Artwork.artist has just 1 value.
I don't know what the problem is =) but it's not working and I've tried a million things. At this point, I'll accept writing SQL queries, but the drupal content database is so incredibly untransparent that I have no idea what to query and how.
Obviously I'd be happiest with an unhacked Views solution, but I'm not getting my hopes up. Anyone experience with relations like this?
You can build dependent relationships that should help you to accomplish this. Use a relationship (Artwork) on exhibition.artworks and a relationship (Artist) on (Artwork).Artist
It would be easier to understand what you're doing with exports of the views & content types.
The database structure for content types in Drupal works as follows;
The node is the base table, with nid as index. Your content types have their own tables, content_type_XXXXXX with all single entry fields (that aren't shared among content types) members of that table. Multiple entry and shared fields get their own table content_field_XXXXXX. All of the tables relate on the nid field, and multiple entry fields use a "delta" to indicate the entry order.

Resources