We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Multi Relation

Development and Programming

Mark Huot's avatar
Mark Huot
587 posts
16 years ago
Mark Huot's avatar Mark Huot

Alright, I know people have been asking for this so I put together a “Multi Relationship” extension that adds another custom field type providing one to many relationships. It behaves the same as any other relationship and uses the same syntax. Anything you specify in a normal relationship should be valid here. The only difference being the code between the ee tags will repeat for as many entries as you selected.

<ul>
<li class="colhead"><strong>Related Entries</strong></li>
{related_entries id="mrelation"}
<li>{title}</li>
{/related_entries}
</ul>

Caution: This extension will only work with EE 1.5.0. Unless the friendly folks at pMachine can help me figure out how to access the Weblog object from the extension. (The third parameter for weblog_entries_tagdata - $this - was only added in version 1.5).

Not Working? Read the top of the extension .php file. There is a workaround if you are running a PHP version <5.

       
Mark Huot's avatar
Mark Huot
587 posts
16 years ago
Mark Huot's avatar Mark Huot

Update: version 1.0.1 fixes a bug when relating entries to galleries.

       
smorello's avatar
smorello
3 posts
16 years ago
smorello's avatar smorello

Hello and first thanks for your extensions.

I have a problem where i can’t find solution.

When i have a field with a multi relationship, if i don’t select a relationship for an entry in the list , there is {REL[][related_services]kWAujMlsREL} displayed for {related_entries id="myfield"}{/related_entries}

Is there a way to test or count the number of related_entries ?

Thank you

Samuel

       
Mark Huot's avatar
Mark Huot
587 posts
16 years ago
Mark Huot's avatar Mark Huot

smorello, version 1.0.2 should fix that problem. grab it at the top of the thread.

       
smorello's avatar
smorello
3 posts
16 years ago
smorello's avatar smorello

Thanks a lot for your reactivity !

       
Mark Huot's avatar
Mark Huot
587 posts
16 years ago
Mark Huot's avatar Mark Huot

No problem. Glad the update helped.

       
bshersey's avatar
bshersey
5 posts
16 years ago
bshersey's avatar bshersey

I am getting that same weird code showing up when I try to use the multi-relationship extension.

{REL[31][Brands]565MMlT6REL}

I think I am doing everything right. My reverse relationship tags are working.

I can see the textarea fields with all my choices in them when I edit an entry. I am using Shift/Click to highlight multiple lines.

And I am using version 1.02, as discussed in the forum.

What would make this happen?

       
Mark Huot's avatar
Mark Huot
587 posts
16 years ago
Mark Huot's avatar Mark Huot

Are you using reverse related entries? I haven’t tested this going reverse.

       
bshersey's avatar
bshersey
5 posts
16 years ago
bshersey's avatar bshersey

Here is the URL: http://www.allergyfreegroceries.com

Click on product listings. This is where I am using straight related entries using your extension and getting the strange code. Click on stores or brands. These are using reverse related entries for the secondary items and seem to be working fine.

The template code is standard related entries code in all cases.

Thanks for your help.

–Scott

       
Jacob Fentress's avatar
Jacob Fentress
37 posts
16 years ago
Jacob Fentress's avatar Jacob Fentress

Mark,

Thank you for the excellent extension - I’ve been wanting something like this for a long time.

One question. Is there any way to implement a way to count the number of relations?

Specifically, I’m trying to do show a list of guests (for a radio program), but I want it to be in sentence format, with commas in the appropriate places. The code I’ve attempted is as follows:

{related_entries id="guests"}
{if count == total_results}<a href="http://myurl.com/radio/guests/{entry_id}">{title}</a>{if:else}<a href="http://myurl.com/radio/guests/{entry_id}">{title}</a>, {/if}
{/related_entries}

Unfortunately, the count for every entry comes out to “1” - at least that’s what I get if I try {count}, so the above code always assumes each count equals the total results because the count and total results show up as “1” even if there are 2 or 15 guests.

Do you have any workarounds for this?

Thanks again for your work. I’ve installed several of your extensions over the past week - all of them excellent.

       
Daniel Walton's avatar
Daniel Walton
553 posts
16 years ago
Daniel Walton's avatar Daniel Walton

Having no entries in a target gallery (not sure if this affects weblog) will throw a fatal error. To fix, add this:

'no_related_entries' =>
'No entries exist yet',

to your lang.multi_relationship.php file, then, line 272 of ext_multi_relationship.php should look like this:

global $DB, $DSP, $EXT, $LANG;

Alternatively wait for an official bug fix.

Sorry Mark just call me impatient 😊

       
bshersey's avatar
bshersey
5 posts
16 years ago
bshersey's avatar bshersey

First, thanks for all of your suggestions. I have been trying to implement all of them. But I am still stuck.

I made the adjustments suggested to the extension files, but I still get the errors.

So I tried Mark’s checkboxes extension. Those seemed to work. I could set up multiple choices and they all showed up, with no gibberish code.

But then I tried to use the query module to create a link back to the related blog that I am calling with the checkboxes. From looking at other code samples and playing around with it, I figured I needed to call exp_weblog_titles and grab {title} and {url_title} to create the link. Using joins, it looks like I need to add in the entry_id from the weblog_data table and child id from the relationships table. All of this works fine. But I am looking for a unique ID to call for this specific item(s). It looks like the rel_ID in the relationships table could work, and I have seen some sample code in these forums that matches the relationships rel_id to a specific field in the weblog_data table.

One problem. My rel_id is a number. The corresponding field in the weblog_data table is a name. So they aren’t comparable in this state.

Is there a way to convert one or the other? Or is there something here that I am missing?

Here’s a good example of some code I picked up and was trying to adjust:

SELECT url_title as brand_url FROM exp_weblog_titles LEFT JOIN exp_relationships ON exp_weblog_titles.entry_id = exp_relationships.rel_child_id

All of the above works fine. But I need that unique ID for this particular entry. I want to make a WHERE clause like this one:

WHERE exp_relationships.rel_id = ‘x’ //where x is the field. But the corresponding rel_id in the field I am looking to match is a number: 62.

Or I could write something without a join like (forgive me if this isn’t exact since I am trying to recreate it here from my head since I wiped my earlier tries out):

SELECT exp_weblog_titles.url_title, exp_weblog_data.entry_id, exp_relationships.rel_id, exp_relationships_childid FROM exp_weblog_titles, exp_weblog_data, exp_relationships WHERE exp_weblog_titles.entry_id = weblog_relationships.childid AND exp.relationships.rel_id = exp_weblog_data.field1).

But once again I run into the problem here that I have one number and one field name. Could someone tell me what I am missing here?

Basically, I am trying to create relationships, with cross-referencing. The main blog is named Products. The sub-blogs are Brands and Stores. I want someone on the products page to be able to click on either specific related Brands or Stores to see all the existing relationships on every page. Then on the Brands page or the Stores page, they should be able to click to see all related products, etc. etc.

Thanks in advance. Previously, I would have done this with ASP and Access. But I think EE will be much easier, once I get this theory down.

–Scott

       
cshontz's avatar
cshontz
9 posts
16 years ago
cshontz's avatar cshontz

Thanks for the great extension! We need away to unselect all entries in the multi-field so that the value is recognized as NULL in our templates.

       
Jacob Fentress's avatar
Jacob Fentress
37 posts
16 years ago
Jacob Fentress's avatar Jacob Fentress

Chris,

I believe you can already unselect entries. If you only have one entry selected (and if you have multiple, click on one to unselect the rest), then hold ctrl (command on mac) and click on that one selection to unselect it.

When you don’t have any entries selected, you can use something like:

{if products != ""}

to check if the field is empty or not. Of course my field in this case is named “products.”

I hope that helps.

       
cshontz's avatar
cshontz
9 posts
16 years ago
cshontz's avatar cshontz
I believe you can already unselect entries. If you only have one entry selected (and if you have multiple, click on one to unselect the rest), then hold ctrl (command on mac) and click on that one selection to unselect it.

OMG - I should’ve known. Thanks, Jacob! It was 12:30 AM - I was runnin’ on empty when I posted that question. 😊

       
1 2 3 Last

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.