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.
Related
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
When opening the query SalesTableListPage from the AOT, you can choose the field MatchingAgreement (shown as "Agreement Header record ID (Record-ID)") in the field lookup. The same is not possible for query SalesUpdate, field MatchingAgreement and several others (which seem to be related to relation fields where the relation is built with a RecId) are not shown in the lookup.
After some research I found out that the reason seems to be the FetchMode property on the joined SalesLine data source. If it is 1:n, the fields are not shown in the lookup. If it is 1:1, the fields are shown in the lookup.
I have not tested this with other tables, but I suspect the same behavior. I also have only tested this with AX 2012 R2 and R3, but I suspect the same behavior in other 2012 versions.
Why does the FetchMode of a joined data source remove some fields from the parent data source in the query dialog?
TL;DR Field lookups in the query dialog do not always work for relation fields that define relations to tables where the AutoIdentification field group's property AutoPopulate is set to No. One case where they not work is when a data source is joined with FetchMode 1:n.
While Alex K's answer has some interesting suggestions, in my case the culprit is the AutoPopulate property on the AutoIdentification field group of table AgreementHeader. In sys layer, this property is set to No and the group contains the fields that are shown in the query dialog field lookup if the relation in the query is 1:1. If this property is switched is to Yes the lookup will show field Agreement header record ID (Record-ID) (and only this field, no matter how the FetchMode of the query relation is defined).
Basically, AX will use the information from the AutoIdentification field group to determine the information shown in the gui in case of surrogate key references/relations. If the AutoPopulate property of the field group is Yes, AX will use the alternate key of the table to determine the fields to use. If no alternate key exists (which is the case for table AgreementHeader), AX uses the relation field. If AutoPopulate is No, the fields defined in the group are used. But as described this option does not work if the relation in the query is not 1:1 (and unfortunately no fallback option like using the relation field seem to have been implemented).
FetchMode AutoPopulate Lookup
1:1 Yes AlternateKey (or Relation) fields
1:1 No AutoIdentification fields
1:n Yes AlternateKey (or Relation) fields
1:n No Nothing
Update:
I came upon this problem again, but with field SalesTaker this time. Turns out that the AutoPopulate property is only part of the story, because it did not solve the problem when set to Yes on table HcmWorker. This table (unlike table AgreementHeader) also has the property ReplacementKey set, which AX uses to populate the AutoIdentification field group. Only after I removed the ReplacementKey no fields appeared anymore in AutoIdentification and the lookup now showed "Sales taker (Record ID)". So bottom line is that the AutoIdentification field group must not contain any fields.
If the dynamic property of both query fields is set to yes, then I'd suspect it has something to do with the properties of one of these relations:
\Data Dictionary\Tables\SalesTable\Relations\Agreement
\Data Dictionary\Tables\SalesLine\Relations\SalesTable
Maybe try adjusting those, refreshing your cache (AOT changes to be picked up), clearing usage data (packed queries can cause problems), and updating XRef (Advanced querying uses XRef, so may not be necessary for standard query functionality)
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.
I have a page which should list nodes. The views is called from a locality page (a taxonomy term page). What I need is almost the same as using the Taxonomy: tid in arguments and passing the tid.
I can't use the term_node table, as (for other reasons) we have a custom table term_node_hierarchy (with nid and tid only). The table term_node_hierarchy is like term_node but also saves the tid of the parents (from an "external" code)
I've been looking for options but still no joy.
Currently I'm building an array of the nid's that should be displayed on the current page, and passing them like print views_build_view('embed', $view, $matching_nids); but the Argument Node: ID states This argument is a single Node ID. As said, only the first node is displayed when printing the views. It would be great if it could filter on more than one nid.
I'm open to any kind of suggestions on how to do this.
Thanks
You could create your own module for this. You could populate the $page_content variable with the results of your own custom query where you allow the user to sort against multiple nids. You could do this a number of different ways. You could display a list of the existing nids with corresponding checkboxes, so that, when the user clicks submit, all the nids that match the selected checkboxes get used in the query. Then you just display the result of that query. That's the easiest way I can think of to offer that degree of flexibility.
(Also posted as http://drupal.org/node/596860)
I would like to create a view showing only those groups of which I am not already a member (or a pending member). However, the obvious way of doing this (take the og_my view and change the filter "Organic groups: Group member" to false) does not work.
The reason is that the SQL query essentially returns one row for every user in the group that matches your conditions. If you're searching for yourself (as in og_my), each group node will only show up once; if you're not searching for yourself, each group node shows up N times, where N is the number of other group members. Thus the groups of which I'm already a member continue to be displayed as long as there's at least one other member.
Does anyone have a way around this?
Thanks, Adrian
You may not be able to achieve this in Views directly as it does not support subqueries. My SQL came out like so:
SELECT node.nid AS nid, node.title AS node_title FROM node node LEFT JOIN og_uid og_uid ON node.nid = og_uid.nid WHERE (node.type IN ('campaign','setting','system')) AND node.nid NOT IN (select nid from og_uid where uid = 1);
It is said you can programmatically forward the results of such a query into the Views system for theming.
Maybe a special handling of the argument Organic Groups:Member of a Group, Exclude Argument option?
I also posted to d.o in hopes of pushing the issue conversation onward.
Wild. OG Views Extra was made available on d.o three days after your first revision of this question. I haven't used it, but looks just like it may do it.
So why install this module? If you need finer-grained control. The
available user options:
Not a Group Member
Group Member or Site Admin
Group Member Only