Tagged: 

Viewing 5 reply threads
  • Author
    Posts
    • #990
      chrisben
      Member

      I have two custom post types, Models and Products, and I need to define a one-to-many relationship so that:
      1. a Product references only one Model
      2. a Model can belong to 0..n Products

      With such a relationship I can either show the current Model of a Product, or list all Products that match this Model.

      From the Edit Product page I want to select a Model and save this relationship.

      I have used “post-relate” but:
      – checkboxes don’t enforce the 1st rule : one can select many models – this is good for a many-to-many relationship.
      – radiobuttons would be a solution, but I would prefer showing a select box

      I have used ‘type’ => ‘select’ and passed an array of Models to ‘choices’, but with that solution I’m losing the reciprocity of the relationship as I have no more ‘post_belongs’/’post_has’. The query to get all Products for a given Model gets ugly as I need to pull the meta for each Product and keep only the ones that match this Model.

      Would it be possible to customize the “post-relate” definition to get either that checkbox UI or a select/radiobutton UI for a one-to-many relationship?

      The problem here is that “type” which is usually used to define the kind of UI (select, checkbox..) you’ll get in the admin is here used to define a relationship.
      I would suggest keeping “type” for the UI type and adding a field “relationship” where one can set “many-to-many”, “many-to-one”, “one-to-one”, “one-to-many”.

    • #998
      Steve
      Keymaster

      Please post some code so we can take a look.

    • #1001
      chrisben
      Member

      Not sure the code will helps as it’s more of a feature request than a bug report.

      Here it is nonetheless:

      myplugin.php:

      $post_types['my_model'] = array(
      'labels' => piklist('post_type_labels', 'Models'),
      'public' => true,
      'supports' => array('title', 'revisions'),
      'rewrite' => array( 'slug' => 'my-model' ),
      'capability_type' => 'post',
      );

      parts/meta-boxes/product.php:

      /*
      Title: Product Reference
      Description:
      Post Type: my_product
      */
      piklist('field', array(
      'type' => 'post-relate',
      'scope' => 'my_model',
      'label' => 'Model',
      'description' => 'Model associated to this product',
      'position' => 'wrap'));

      From that basis I’d like to define the relationship between a Product and its Model via a selectbox instead of the current checkbox UI. The reasons are detailed in the first post.

    • #1006
      Steve
      Keymaster

      @chrisben– Sorry, didn’t realize it was a feature request. This is actually a bit harder then you would think. Something we want to do in the future, but right now POST RELATE has to be checkboxes.

    • #3957

      Has there been any progress on this request? I’m in a similar situation, though my post types are called something else ;-).

    • #3960
      Steve
      Keymaster

      @woutervanvliet– Welcome to the Piklist community!

      We are in feature lockdown right now as we get Piklist to a stable 1.0 version. Once that’s done, we will start rolling out new features.

Viewing 5 reply threads
  • You must be logged in to reply to this topic.