Giter Site home page Giter Site logo

Collection relations about cockpit HOT 23 CLOSED

agentejo avatar agentejo commented on May 6, 2024 3
Collection relations

from cockpit.

Comments (23)

aheinze avatar aheinze commented on May 6, 2024

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

from cockpit.

maxstrebel avatar maxstrebel commented on May 6, 2024

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

from cockpit.

StevenDevooght avatar StevenDevooght commented on May 6, 2024

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!

from cockpit.

aheinze avatar aheinze commented on May 6, 2024

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

from cockpit.

bainternet avatar bainternet commented on May 6, 2024

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

from cockpit.

aheinze avatar aheinze commented on May 6, 2024

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

from cockpit.

aheinze avatar aheinze commented on May 6, 2024

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

from cockpit.

bainternet avatar bainternet commented on May 6, 2024

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

from cockpit.

bainternet avatar bainternet commented on May 6, 2024

@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.

from cockpit.

StevenDevooght avatar StevenDevooght commented on May 6, 2024

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!

from cockpit.

aheinze avatar aheinze commented on May 6, 2024

@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

from cockpit.

StevenDevooght avatar StevenDevooght commented on May 6, 2024

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?

from cockpit.

maxstrebel avatar maxstrebel commented on May 6, 2024

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

from cockpit.

crealx avatar crealx commented on May 6, 2024

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 :(

from cockpit.

crealx avatar crealx commented on May 6, 2024

someone can help me ?

from cockpit.

TomCahill avatar TomCahill commented on May 6, 2024

@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.

from cockpit.

crealx avatar crealx commented on May 6, 2024

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

from cockpit.

aheinze avatar aheinze commented on May 6, 2024

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());

from cockpit.

StevenDevooght avatar StevenDevooght commented on May 6, 2024

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?

from cockpit.

aheinze avatar aheinze commented on May 6, 2024

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.

from cockpit.

StevenDevooght avatar StevenDevooght commented on May 6, 2024

Aha ok, forgot about the MongoDB cursor.

from cockpit.

aaronfischer avatar aaronfischer commented on May 6, 2024

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

from cockpit.

royduin avatar royduin commented on May 6, 2024

+1

from cockpit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.