Core Data Relationships Binding in IB - objective-c

I have a simple program that stores purchase information in a core data store. The model is similar to the following.
Entities:
Student(lastName,firstName) relationship to (BoughtPackage)
BoughtPackage relationship to (Payment) and (Package)
Payment(type,amount)
Package(name,price)
Structure looks like
I would like to first display the list of students in a table, then format the purchases made my that individual student in a details table.
So far, I have been able to create an NSArrayController to hold the data of the Student entity, but cannot figure out how to propagate the purchase detail table. How would I accomplish this using IB alone, or is it possible? If so, how would I do it programmatically?

Yes it is possible to do this mostly in IB without writing any code. But thats too broad a question for a SO answer
You really need to read
https://developer.apple.com/library/mac/#documentation/cocoa/conceptual/cocoabindings/cocoabindings.html
and theres a tutorial in the docset titled
Introduction to Developing Cocoa Applications Using Bindings: A
Tutorial
which i can't find a web link for. Just search the title.
But sort out your model too. It looks like all your relationships are one-to-one
For example. I would expect that a Student may have many BoughtPackages hence a one-to-many relationship there and the same with BoughtPackage to Payment.
Good luck

Related

How to know if this entity diagram is properly normalized? With the picture below, would it be ok to build a simple database?

Ticket Booking Entity Diagram
I am practicing to build databases. I just modeled this in draw.io before building a physical model. However, I am confused if this model is a proper one. What should be the best way to implement this ticket booking database? What aspect of this model needs to be changed, or what action of design should not be followed? Please help in this regard.
No, this model wouldn't work.
In your model tickets are associated with the cinema, which doesn't make sense.
Your timings also have nothing to do with Movie. While you've got the right ID there your relationship lines are a bit wonky.
There are a couple of different ways of doing it, but based on what you've got so far I'd go for something along these lines:
The way to think about it is what has what: A Cinema has times that it can show movies. A movie is shown at a time. A time has seats that are sold via tickets to users. You can certianly put the MovieID into the Tickets or Seats table for your foriegn keys, but the above is how I see the main relationships going.
Depending on how you want to model it you could make it that cinemas have movies, and movies have timings. I went with Cinemas having timings, because that feels more right to me. You may have a different opinion.

Embeddable vs one to many

I have seen an article in Dzone regarding Post and Post Details (two different entities) and the relations between them. There the post and its details are in different tables. But as I see it, Post Detail is an embeddable part because it cannot be used without the "parent" Post. So what is the logic to separate it in another table?
Please give me a more clear explanation when to use which one?
Embeddable classes represent the state of their parent classes. So to take your example, a StackOverflow POST has an ID which is invariant and used in an unbreakable URL for sharing e.g. http://stackoverflow.com/q/44017535/146325. There are a series of other attributes (state, votes, etc) which are scalar properties. When the post gets edited we have various versions of the text (which are kept and visible to people with sufficient rep). Those are your POST DETAILS.
"what is the logic to separate it in another table?"
Because keeping different things in separate tables is what relational databases do. The standard way of representing this data model is a parent table POST and child table POST_DETAIL with a defined relationship enforced through a foreign key.
Embeddable is a concept from object-oriented programming. Oracle does support object-relational constructs in the database. So it would be possible to define a POST_DETAIL Type and create a POST Table which has a column declared as a nested table of that Type. However, that would be a bad design for two reasons:
The SQL for working with nested tables is clunky. For instance, to get the POST and the latest version of its text would require unnesting the collection of details every time we need to display it. Computationally not much different from joining to a child table and filtering on latest version flag, but harder to optimise.
Children can have children themselves. In the case of Posts, Tags are details because they can vary due to editing. But if you embed TAG in POST_DETAIL embedded in POST how easy would it be to find all the Posts with an [oracle] tag?
This is the difference between Object-Oriented design and relational design.
OO is strongly hierarchical: everything is belongs to something and the way to get the detail is through the parent. This approach works well when dealing with single instances of things, and so is appropriate for UI design.
Relational prioritises commonality: everything of the same type is grouped together with links to other things. This approach is suited for dealing with sets of things, and so is appropriate for data management tasks (do you want to find all the employees who work in BERLIN or whose job is ENGINEER or who are managed by ELLIOTT?)
"give me a more clear explanation when to use which one"
Always store the data relationally in separate tables. Build APIs using OO patterns when it makes sense to do so.

How to insert a new object into an entity and create a relationship to an existing object in another entity in Core data Relationships

I am wondering if anyone would be kind enough to help me with a core data related problem. I am building a iPhone app and now need to create a relationship from one entity to another.
I am new to core data, objective c and quite frankly the whole app development process so if you do have an answer please bare in mind I may find it hard to understand :-( I have spent a very long time scanning the web and reading Apple's documentation and just can't get my head around this problem.
Any help would be very much appreciated, thank you.
maintaining a relation is confusing in core data.I would like to refer magical records library for the core data relations it will work on the base of key value coding pair need not to maintain relations if we want to fetch the data from the another table we can fetch using common attribute from that table .please refer this link to understand about one to one and one to many relations https://www.raywenderlich.com/14742/core-data-on-ios-5-tutorial-how-to-work-with-relations-and-predicates .Hope this will help you

How to store a List or Collection in a dataset table/column? (VB.NET)

I have a dataset table with various columns that are created during form load.
These columns are currently either system.double or system.string types.
And it is displayed in a datagridview.
This works fine.
But I need another column that can store a "list" or some collection in the data table.
A list of strings would do but a custom class would be better.
How is this usually done?
I have spent literally weeks googling this and I dont know where to start. The more I have looked the more confused I have ended up. I end up with more questions than answers, like how is it displayed in the datagridview? I read about a combo box?
I hope someone can give me some pointers in how to get this achieved. I've not posted any code as I think its more the theory of this I need help with.
What you are asking for has does have multiple concerns for most programmers. The storage of data (#1) and the displaying of said data to the user (#2)
For #1 I recommend the .net entity framework. It gives support for storing, querying and updating classes for use in the database. Through most tutorials that I have found it is possible to model the structure of the database tables and their relations and then build a database around that model OR to use an existing database and create entities (entity framework's class objects) around the existing structures and relationships.
Here is a link to a very good beginner tutorial that I have used before: CodeProject Entity Framework Tutorial for Absolute Beginners
For #2 I can recommend the Windows Presentation Foundation. It has lots of bells and whistles to make using a data source and displaying the relevant dependent data very easily through its unique method of data binding. From the tutorials I have used on PluralSight it can be as easy as dragging and dropping from an imported data source like the entity framework database. Alternatively, one can just handle selected row changes for one data grid and then show the dependent data in another data grid.

DDD: Modeling M:N relation between two roots where the relation itself carries semantic meaning

Update Edited to reflect clarifications requested by Chris Holmes below. Originally I was referring to a Terminal as a Site but changed it to better reflect my actual domain.
At heart, I think this is a question about modeling a many to many relationship between two root entities where the relationship itself carries some semantic meaning.
In my domain
You can think of a Terminal as a branch location of our company
A Terminal can have a relationship with any number of customers
A customer can have a relationship with any number of terminals (standard many to many)
A customer\terminal relationship means that a customer can potentially store products at the Terminal
This relationship can be enabled\disabled. To be disabled merely means you are temporarily not allowed to store product, so a disabled relationship is different from no relationship at all.
A customer can have many Offices
A Terminal that has a relationship with a customer (enabled or not) must have a default office for that customer that they communicate with
There are some default settings that are applied to all transactions between a Customer and a Terminal, these are set up on a Terminal-Customer Relationship level
I think my objects here are pretty clear, Terminal, Customer, Office, and TerminalCustomerRelationship (since there is information being stored specifically about the relationship such as whether it is enabled, default office, ad default settings). Through multiple refactorings I have determined that both Terminal and Customer should probably be aggregate roots. This leaves me with the question of how to design my TerminalCustomerRelationship object to relate the two.
I suppose I could make the traversal from Terminal to TerminalCustomerRelationship unidirectional toward the relationship but I don't know how to break the relation from the relationship to the customer, especially since it needs to contain a reference to an Office which has a relationship to a Customer.
I'm new to this stuff and while most of DDD makes perfect sense I'm getting confused and need a fresh outlook. Can someone give me their opinion on how to deal with this situation?
Please note that I say Relationship not relation. In my current view it deserves to be an object in the same way that a Marriage would be an object in an application for a wedding chapel. Its most visible purpose is that it relates two objects, but it has other properties that rightfully belong to it as well.
By your description, you definitely need a "TerminalCustomerRelationship" entity to track the associated information. I would also convert the 'IsEnabled' flag into a first class 'Event' entity with a timestamp - this gives you the ability to save a history of the state changes (a more realistic view of what's happening in the domain.)
Here's a sample application (in VS2008) that refects your problem. You can tweak/test the code until the relationships make sense. Run "bin/debug/TerminalSampleApp.exe" and right-click "Terminal->Create Example" to get started.
Let me know if you find it useful.
Names can often clarify an object's responsibilities and bring a domain model into focus.
I am unclear what a Site is and that makes the entire model confusing, which makes it difficult for me to offer better advice. If a Site were a Vendor, for instance, then it would be easy to rename SiteCustomerRelationship as a Contract. In that context it makes perfect sense for Contract to be its own entity, and have the the model look like Vendor-Contract-Customer-Office.
There are other ways to look at this as well. Udi has a decent post on this sort of many-to-many relationship here.
You should not have a object Like SiteCustomerRelationship, its DB specific.
If its truly DDD you should have a Relation like:
Aggregate<Site> Customer.Site
IEnumerable<Aggregate<Office>> Customer.Offices
and perhaps
Aggregate<Office> Customer.DefaultOffice