Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection relations #54

Closed
StevenDevooght opened this issue Mar 8, 2014 · 23 comments
Closed

Collection relations #54

StevenDevooght opened this issue Mar 8, 2014 · 23 comments

Comments

@StevenDevooght
Copy link
Contributor

Adding a relation field to the collection type would be a great enhancement. This would make it possible to link collections together.
Content editors would get a search dropdown where they can search through the referenced collection type.

I don't know how difficult it is to add something like that to the current code base or if it even fits the lightweight philosophy of this project.

@aheinze
Copy link
Member

aheinze commented Mar 10, 2014

you're right, it is not that easy...but is's on my todo list

@maxstrebel
Copy link

+1 from me. This would also solve my need for taxonomies.

@StevenDevooght
Copy link
Contributor Author

I started to work on a proof of concept for the relations. You can see the result here: https://github.com/StevenDevooght/cockpit/tree/collection_relations

For now it only supports one to one relations.

I added a 'find' method to the collections public api so the populate method can be called on the ResultSet class.

cockpit("collections")->find('CollectionTest')->populate('test')->toArray();

It's a bit rough around the edges, but it's a start. Your input would be highly appreciated!

@aheinze
Copy link
Member

aheinze commented Apr 29, 2014

@StevenDevooght You provided some ideas that I need to elaborate, thanks!

@bainternet
Copy link

+1 for Collection relations, Actually its the only thing holding me from using cockpit in a bunch of projects i have lined up.

@aheinze
Copy link
Member

aheinze commented May 5, 2014

I'm already working on solving this issue :-)

@aheinze
Copy link
Member

aheinze commented May 13, 2014

@StevenDevooght I have a first solution for linking collections in the master branch, maybe you want to try it out?

@bainternet
Copy link

@aheinze Just tested it and it looks like its getting the job done.

@bainternet
Copy link

@aheinze Some feedback,

It would be nice to link to more the one entry for example if i have a posts collection and categories collection then a post could be linked in to more then on category.

Also a nice feature would be to define which field of the linked entry i want to display on entries list page, example i have a posts collection and categories and my category collection as a field named "NAME" then on the posts entries list i want it to show the value of the "NAME" field of the linked categories instead of the linked category ID.

Nice progress and thanks for putting your time on this.

@StevenDevooght
Copy link
Contributor Author

I didn't find time yet to give this a test, but I will do for sure.

As @bainternet suggested the logical next step is to add one to many linked collections which shouldn't be to difficult with the base logic already in place.

Keep up the good work!

@aheinze
Copy link
Member

aheinze commented May 14, 2014

@bainternet thanks for testing! the link collection field shows the same fields you define as "Fields on entries list page" on the collection edit page.

@StevenDevooght + @bainternet to define multiple collections links I want to go a step further and make it possible for every field, with a "multiple" setting that you can set in the collection edit view

@StevenDevooght
Copy link
Contributor Author

Just had a quick look and it's getting there!

Picking a linked collection is pretty straightforward using the dialog, which can even be enhanced using search filters.

Any idea what the public api will look like?

@maxstrebel
Copy link

I also tested it right now and works like a charm! Thumbs up for the other changes, too.

@crealx
Copy link
Contributor

crealx commented Jun 20, 2014

Great improvment !
I'm trying to use it.
I have a collection col, with a linked collection coltype. How can i read the coltype element of the col ?
Trying this :

 <?php foreach(collection("col")->find() as $item): ?>
<h5>< ?=$item["nom"];?></h5>
<?php foreach($item["coltype"] as $col): ?>
<h6>< ?=$col["coltype"];?></h6>
 <?php endforeach; ?>
<?php endforeach; ?>

Doesn't work :(

@crealx
Copy link
Contributor

crealx commented Jul 4, 2014

someone can help me ?

@TomCahill
Copy link

@crealx Not to sure if its the problem but if you look at lines 2 and 4. I think the blank space between "<" and "?" will stop PHP from picking up to process it.

@crealx
Copy link
Contributor

crealx commented Jul 4, 2014

;) thanks, but it's just a mistake in the copy/paste... but that doesn't work :(

@aheinze
Copy link
Member

aheinze commented Jul 10, 2014

I just commited a helper function to populate a collection resultset with linked collections:

522a28a#diff-8b75f95e1a5b573ee0f68ddecbfa9f86R47

Usage:

$result = cockpit('collections')->populate('colname', collection("colname")->find());

// or

$result = collection_populate('colname', collection("colname")->find());

@StevenDevooght
Copy link
Contributor Author

If I want to populate all linked collections configured on for instance a 'News' collection I have to use the following method which works flawlessly.

$result = collection_populate('News', collection('News')->find());

What confuses me is the first parameter of the collection_populate function. The scope of the ResultSet is already dealing with 'News' items. Is it necessary the repeat this again with the first parameter or am I missing something here?

@aheinze
Copy link
Member

aheinze commented Jul 15, 2014

the point is, that you don't have a context...the resultset can be either an array or a MongoLite/MongoDB cursor. The MongoLite cursor knows the context, the MongoDB cursor not. I know it looks strange...but well, it works for now.

@StevenDevooght
Copy link
Contributor Author

Aha ok, forgot about the MongoDB cursor.

@aaronfischer
Copy link

Would these collection links and their linked data be accessible from the JS/REST API as well?

@royduin
Copy link

royduin commented Oct 21, 2015

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants