Tagged: relationships
- This topic has 5 replies, 3 voices, and was last updated 6 years, 7 months ago by
Steve.
-
AuthorPosts
-
-
August 14, 2013 at 5:31 am #990
chrisbenMemberI 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 ProductsWith 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 boxI 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”. -
August 15, 2013 at 8:58 am #998
SteveKeymasterPlease post some code so we can take a look.
-
August 21, 2013 at 9:35 am #1001
chrisbenMemberNot 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.
-
August 22, 2013 at 8:13 pm #1006
-
July 2, 2015 at 10:53 am #3957
woutervanvlietMemberHas there been any progress on this request? I’m in a similar situation, though my post types are called something else ;-).
-
July 2, 2015 at 9:02 pm #3960
SteveKeymaster@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.
-
-
AuthorPosts
- You must be logged in to reply to this topic.