doctrine 1.2 - doctrine collection auto group by id - collections

I have a sql view with multiple tables joined with union all. The view has a collumn id which is the primary key for each record (which can came from different tables).
The problem ism becuase the view results from a union, there might be more than one row with the same id.
In this cases Doctrine_Collection seems to automaticly group all the records by the id collumn making some records to disapear.
Is there any way to change this behavior?

If you really need to combine those records in a union, one way around that problem is to alias the id field for each subquery or table so that the id fields don't get combined.

Related

How to get all related information with a single SOQL query?

I have three objects: Master, Join, and Item. Join has a Master-Detail relationship to Master called Master__c and a lookup relationship to Item called Item__c.
Given a list of Master Ids, I want all of the Master records along with the names of the related Item records through Join. How do I do this?
If I understand the objects and relationships you described correctly,
Master is the parent object and can have zero or more Join records.
Join is a child of Master and can have zero or 1 reference to an Item.
If so, you can use a SOQL query like this:
select id, name, (select name, item__r.name from Master__r) from Master where id in ()

Is there any way to retrieve items from dynamodb table by applying filter condition on primary key

I am trying to fetch items from a dynamodb table with some condition on primary key and I don't have any other values with me.I just know that some of records in the table have a different pattern for primary key (like contains a hyphen in it) which others don't.How do I achieve this in a simple way..Do I need to Scan the complete table get the result and filter the desired records
Some thing like "Select * from Student where Id like '%-%', as we do in sql
You will need to do a scan and filter. If the table has a lot of items it could be a slow and expensive process.

Keep record even after deleting from application

I have two tables, category (pk) and foreign key table Item(fk).
In item table have itemid, item name,category I'd....and this category I'd is foreign key column with primary table...which is having category I'd, Category name.
And I have relationship between category table as parent and. Item table as child table....category I'd is the relationship between them. When I delete records based on itemid the records should be deleted from the application but maintained at backed level..as I do not want duplicate item...even I have deleted from application.
At Application level I am doing these things with textboxes for and drop down list which should category names.
If I have got you correctly, what you want to do is, maintain the data in the database table even if you delete it from the application interface.
If that is the case, you simply can add a column like 'isDeleted' in both of the tables in the database. In the delete event, just fire the update statement instead of actually deleting the record and set the 'isDeleted' field value to 'True'. At the time of displaying data from the tables, just select the records having 'isDeleted' value equals to 'False'.

Linq query returning Less records than Sql Query

I am facing a big problem with simple linq query.. I am using EF 4.0..
I am trying to take all the records from a table using a linq query:
var result = context.tablename.select(x=>x);
This results in less rows than the normal sql query which is select * from tablename;
This table has more than 5 tables as child objects (foreign key relations: one to one and one to many etc)..
This result variable after executing that linq statement returns records with all child object values without doing a include statement..
I don't know is it a default behavior of EF 4.0 ..
I tried this statement in linqpad also..but there is no use...
But interesting thing is if I do a join on the same table with another one table is working same is sql inner join and count is same..but I don't know why is it acting differently with that table only..
Is it doing inner joins with all child tables before returning the all records of that parent table??
please help me..
This table has more than 5 tables as
child objects (foreign key relations:
one to one and one to many etc)..
This result variable after executing
that linq statement returns records
with all child object values without
doing a include statement..
So we are probably talking about database view or custom DefiningQuery in SSDL.
I described the same behavior here. Your entity based on joined tables probably doesn't have unique identification for each retruned row so your problem is Identity map. You must manually configure entity key of your entity. It should be composite key based on all primary keys from joined tables. Entity key is used to identify entity in indenty map. If you don't have unique key for each record only first record with the new key is used. If you didn't specify the key manually EF had infered its own.
The easiest way to troubleshoot these types of issues is to look at the generated SQL produced by the ORM tool.
If you are using SQL Server then using the SQL Profiler to view the generated SQL.
From what you are describing, a possible explanation might be that your relationships between entities are mandatory and thereby enforcing INNER joins instead of LEFT OUTER joins.

How should I go about making sure the value pairs in this table are unique?

I am using Visual Web Developer and Microsoft SQL server. I have a tag table "Entry_Tag" which is as follows:
entry_id
tag_id
I want to make the entry_id and tag_id pairing unique. A particular tag can only be applied to an entry once in the table. I made the two columns a primary key. They are also both foreign keys referencing the ids in their respective tables. When I dragged the tables into the Object Relationship Designer it only showed a relationship line between either "Entry_Tag" and "Entry" or when I tried again between "Entry_tag" and "Tag".
The "Entry_tag" table should have a relationship with both "Tag" and "Entry".
How do I go about doing this?
In general, you can add a unique constraint on the table that includes both columns. In this case, including both of the columns in the primary key should have already done this. If you have relationships set up for each field to other tables, then I believe those relationships should be displayed in the query designer... I see no cause for this given the information you've provided - perhaps you need to post more information.
Create an UNIQUE INDEX to for entry_id and tag_id.
CREATE UNIQUE INDEX index_name ON table (entry_id, tag_id)

Resources