Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow one-to-many, many-to-one connections #28

Closed
cyberhobo opened this Issue · 10 comments

3 participants

@cyberhobo

Given the setup in the Basic Usage wiki page, I'm wondering if I can write a query for pages that have no connected posts?

My guess is that this would require at least a new query variable to achieve.

@scribu
Owner

Indeed. Perhaps 'not_connected' => 'any'.

May I ask what the use-case is?

@cyberhobo

It's kind of a convoluted use case from a client, and I admit this may be too rare to bother with. Simplified a bit: users can a write a post of type B about another post of type A. I'm trying to give them a list of type A posts they haven't already written about.

@scribu
Owner

Actually, I've heard at least one other user want something like this:

http://wordpress.org/support/topic/plugin-posts-2-posts-exclusive-relations-er-monogamy

He ended up using an additional query + 'post__not_in', which works, but might stop working if you have millions of posts.

@scribu
Owner

How about if p2p_register_connection_type() could guarantee this:

$my_connection = p2p_register_connection_type( array(
  'from' => 'post',
  'to' => 'page',
  'cardinality' => 'one-to-many',
) );

And then, $my_connection->get_connectable( 'page' ) would return only posts that aren't already connected to any page.

The default cardinality would be 'many-to-many'.

@cyberhobo

I'll try something like that, thanks. I should be able to limit excluded posts to an author to keep the list manageable. BTW that link should be

http://wordpress.org/support/topic/plugin-posts-2-posts-exclusive-relations-er-monogamy-

@cyberhobo cyberhobo closed this
@scribu
Owner

Actually, I want to implement this.

I had openend #16 earlier, but now I have a clearer picture of what's needed.

@scribu scribu reopened this
@cyberhobo

Missed your last comment - that feature seems like it would fit my situation (and be very cool :).

@doolin

You know, really, modeling ActiveRecord associations would be incredible: belongs_to, has_many, has_one, etc. Dream the impossible dream, but...

@scribu scribu closed this in 36047b4
@scribu
Owner

@doolin: ActiveRecord associations are interesting, but they're way out of scope for this issue.

@scribu
Owner

Too lazy to create a new issue, so here goes:

ActiveRecord associations create foreign keys based on cardinality; P2P always uses the wp_p2p table.

Also, p2p_register_connection_type() tries to be impartial, whereas AR associations are focused on one end of the connection.

So, I don't think there's much benefit in replacing the 'cardinality' arg with 'has_one' or 'has_many'.

If you want ActiveRecord in PHP, see http://www.phpactiverecord.org/

@dbernar1 dbernar1 referenced this issue from a commit in dbernar1/wp-posts-to-posts
@scribu first pass at 'cardinality' arg. see #28 9320e02
@dbernar1 dbernar1 referenced this issue from a commit in dbernar1/wp-posts-to-posts
@scribu check other cardinality in get_connectable(). closes #28 677974e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.