OrientDB Find vertex containing relationship to anther vertex without further relationship - orientdb

I have found similar questions but nothing has really worked for me yet so I'm hoping for a fresh answer.
I have a graph but let me simplify the problem here. I have three classes (Warehouse, Product, Item). A warehouse is where products are made. A Product is a definition of something. And item is an instance of a product we track as inventory.
The relationships look something like this.
Warehouse->[produces]->Product->[created]->Item
I am trying to find all Warehouses that have a Product that have no Items. Is this possible in the SQL syntax? If not is there another way?

If you've modeled it using Graph API you can do something like:
select from Warehouse where out('produces').out('created').size() == 0

Related

Modeling an inverse relationship in Core Data

Relationships in Core Data just confuse me. I've read and read, but I just don't get it. I guess it doesn't help that I'm usually frustrated when reading. I want to do something really simple:
I have an Entity called Pictures and an Entity called User. I want Users to be able to like and tag other people in pictures, so each Picture entity has two relationships:
Picture Entity:
UsersWhoLikedThePicture (to-many):
Destination: User
Inverse: Picture
UsersWhoAreTaggedInThePicture (to-many):
Destination: User
Inverse: Picture
But this is causing so much mix up in use, that I can't even begin to describe. It's inconsistent. Someone likes a picture causes them to be removed as a tagged user, and like one picture causes your likes from all other pictures to be removed. Ahhh it's such a mess..does my structure look ok? How would I model this?
In addition to Matthias Bauch answer, I could give you some hints to understand relationships.
First, when you deal with Core Data you have to think in term of objects. By means of this astraction you could think at your model as a graph where nodes are the entities that you created in the model, while relationships are the links among those entities.
Now, about relationships, they could be of different types: one-to-one, one-to-many and many-to-many. Based on the type of relationships you have, you can create different link in the objects graph. For example, if a User has a to-many relationship with Picture, it means that each instance of object (of type NSManagedObject) has a link to different Pictures. User works as the source, Pictures, as the destination.
Inverse relationships are used by Core Data to maintain the graph consistency. In particular, they are useful when you deal with delete rules.
Each relationship has a delete rule associated with it. Cascade means that if you delete an object, say the User, Core Data will delete the object (the Pictures) linked to it for you. Deny doesn't allow to delete an User if there are Pictures linked to it. Nullify means the link from a Picture to a User will be broken. It doesn't mean that the objects are deleted. In terms of object graph, it means that you haven't anymore a link between those objects. No Action means that the source is deleted, the destination is always there and it continues to point to an object that doesn't exist anymore. So, unlike Nullify, you need to broke that link manually. If not you could have a graph inconsistency. Try to avoid this type of relationship.
If you want to know something else, let me know.
EDIT
Take a look at Core Data Programming Guide Relationships section for further info.
I don't know if this is even possible, but it sounds like you used the same inverse target for two relationships. Don't do that.
The right way would be something like this:

What is Objectified Relationship?

I am not sure if I should be asking this here or at the programmers site. I came across "objectified relationship" while researching recursive saving in llblgen framework...I then searched stackoverflow (yes, first) and then google. I then came across a brief (related) topic on nHibernate.
I have an idea what it is but is there a detail description or explanation on it?
The relationship is an object itself, not just a connection. In a database the relationship would be represented as a row in a table rather than just as a UID in a column referencing another table. In a graph the relationship would itself be a node rather than 'just' an edge.

With WCF Data Services, is it possible to use the $expand command on joint tables

I am trying to do something fairly easy to understand with WCF data services, but can't find how to do it.
I have 3 table, Customer, Product and a joint table Customer_Product linking the two other tables (a basic n to n relationship):
Customer <= Customer_Product => Product
I want to get a customer and its products in the same query, so I would like to do something like:
/Service.svc/Customers(23)?$expand=Products
But it tells me that there is no Products navigation property on the table Customer.
The only option that I found is to do:
/Service.svc/Customers(23)?$expand=Customer_Product
and then make another call to get the Product details.
Is there a clean way to do this?
Thanks a lot in advance.
The many to many relationships are usually modeled by the service by hiding the join table (if the only thing it stores is the relationship and there's no data in it). If you're using EF in the service this should be pretty easy to do.
If you do need to expose the join table for some reason, then you can issue a query like:
/Service.svc/Customers(23)?$expand=Customer_Product/Product
(expands can be multiple levels deep). Of course reading the results will be a bit more complicated because of the two levels there, but you do get the data you need.

Modelling entity types using Core Data

I'm working on my first app using Core Data and I need to assign a type (with an associated name attribute) to a couple of entities.
Below is my object model so far.
The room and item types will be updated from time to time over the network.
Is this the best way to implement this using Core Data? Thanks :)
Edit: To try to explain better: for example, rooms may be Bedrooms, Kitchens etc. Items can be Aircon, Security Camera etc. The only difference between the different room and item types is the name text. The list of valid name texts will be updated so I don't want to hard code it in the app. Also, the user can create multiple rooms and items of the same type, which is why they are numbered (roomNumber,itemNumber)
improved Core Data Model Image http://img42.imageshack.us/img42/8458/picture6c.png
Nick, try and avoid the temptation of thinking of Core Data as a database. Design your model from the point of view looking at using the objects in your code.
i.e. your relationship properties are collections (or singluars) of the related thing.. you should rename the relationship JobLocation.JobLocationToRoom as just JobLocation.rooms
And yes, using Core Data will be quite straight forward, but it's hard to give you a definitive answer with such a vague question.
Perhaps my question wasn't clear, but I found the answer in the Apple iPhoneCoreDataRecipes demo code
The relationship I wanted to model is similar to Recipe -> RecipeType.
In addition to the other answers, you don't need to model separate ID attributes. Core Data managed objects automatically have managed object IDs that are handled for you entirely behind-the-scenes by the framework.

removing a circular DB relationship

How can I get rid of a circular relationship in my db structure. I have an entity called Item. An item can have a sub item/s (circular relationship). An item can have more than one rate depending on what financial year it is(rate_per_year entity created for that purpose and a 1-m relationship). If an item has a sub item, then it may have no rates(I need this relationship broken if a sub item is created). Any help will be greatly appreciated.
Thanx in advance
If the item->subitem chain can continue at multiple levels, then you have no real choice but it like you have it. If only a top-level item can have subitems, then you can break out the structure into two tiers, possibly item and group where only item can have a rate, and may or may not have a group.
What you have described is the Parts Explosion Problem. When I was at university, this was something that could not be solved by relational databases, and was one of the main selling points of Object Oriented Databases. It appears that things may have moved on now, depending on which DB you are using.
This page looks interesting
Sql Anywhere Users Guide - Parts explosion problems, but unfortunately you didn't mention which RDBMS you were using. It also appears to be supported by SQL Server 2005, so perhaps you will be in luck. Try searching for "Recursive SQL queries" and whichever DB you are using.
Best of luck