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

Extension: MD Simple Relation. Creates a "simple" relationship field, storing only the entry_id.

Development and Programming

Ryan M.'s avatar
Ryan M.
1,511 posts
17 years ago
Ryan M.'s avatar Ryan M.

I was having an impossible time getting reverse_related_entries to work with categories - all I needed to do was store a related entry’s entry_id in a field - so that’s all this does.

Simple Relation looks and works identically to a native Relationship field type, but it avoids the relationship table altogether, creating a very “simple” relationship by storing only the related entry_id. This way you can use EE’s built-in weblog:entries “search” parameter to filter entries - which might be easier than trying to mess with Reverse Related Entries and multiple embeds when trying to sort by category. It may have other uses, but that’s all I need it for. Might save you from having to use the Query module, too.

See this post for an example of exactly how I’m using Simple Relation.

You can download Simple Relation here.

       
evasion's avatar
evasion
58 posts
17 years ago
evasion's avatar evasion

Looks nice, I’ll try it soon. Thanks for sharing it !

       
Grant B's avatar
Grant B
5 posts
17 years ago
Grant B's avatar Grant B

How diificult would it be to extend Simple Relation to deal with one-to-many relationships, where multiple related entries can be selected. I guess it would need to store an array of entry ids instead of a single number. This would keep all the benefits, whilst making it similar to this plugin.

       
evasion's avatar
evasion
58 posts
17 years ago
evasion's avatar evasion

Grant B, what your talking about seems similar to this, no ?

       
Grant B's avatar
Grant B
5 posts
17 years ago
Grant B's avatar Grant B

evasion, the idea I have is similar to both Mark Huot’s multi-relation and to the Playa plugin. I will need to test whether each of them works with categories. It is great to see different plugins available that enable very flexible approaches to dealing with multiple-approaches.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
17 years ago
Ryan M.'s avatar Ryan M.
How diificult would it be to extend Simple Relation to deal with one-to-many relationships, where multiple related entries can be selected.

For me it would be difficult because:

1) I’m not super adept with PHP, so I’d have to figure out how to store the data 2) I’d have to (want to…) figure out a way to designate, per field, whether you wanted to store multiple id’s or a single id for that field (I do have an idea about how to do that, actually) 3) I’m a perfectionist - so I’d love to make it so you can drag and drop multiple selections to reorder them. 4) I’m so sleep-deprived this week that all of the above makes me want to weep. I want to go outside.

       
Grant B's avatar
Grant B
5 posts
17 years ago
Grant B's avatar Grant B
4) I’m so sleep-deprived this week that all of the above makes me want to weep. I want to go outside.

I’m going to take a look at the other possibilities to see how well they work with categories and then give some thought to the design to see how necessary categories are – so hopefully won’t be making any requests that will cause further weeping.

I’m looking forward to using your plug in for simpler relationships though. That is definitely going to let me get some things done on one of my existing sites.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
17 years ago
Ryan M.'s avatar Ryan M.

I do think I got this to work with Galleries, too. Check out this post, and the two screenshots there.

       
lukemcr's avatar
lukemcr
154 posts
16 years ago
lukemcr's avatar lukemcr

I’ve imported several thousand weblog entries into my EE install, and took the time to make sure that all of the relationships were set up right. Now that I’ve got the data imported, I’m trying to do stuff with it: and I find myself somewhat stymied by EE’s inability to search: by a relationship field.

I’ve been playing around with Simple Select, and I think it will do just what I need. My question, though, is: How can I convert all of my old relationships in to Simple Select relationships? Changing the field_type in exp_weblog_fields to simplerel from rel just erases my data.

Is this possible w/o reimporting everything? Or will I have to establish new “simplerel” relationships?

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

I’m not too familiar with the Relationships table - and this little extension was designed to stay away from it. When you say “Simple Select” do you mean “Simple Relation”?

I would imagine it wouldn’t be too difficult to write a query that copies part of the relationship data (just the ID needed) into the field for the Simple relationship - all the simple relationship is is a number, nothing else.

In order to maybe save you some work - what are you finding that the “real” relationship field isn’t doing for you? How are you trying to search?

       
lukemcr's avatar
lukemcr
154 posts
16 years ago
lukemcr's avatar lukemcr

Well, I’m making a bus schedule site. I’ve got three weblogs that hold the timetable data: one for routes, one for stops, and one for stop times. The stop times weblog has the time the bus stops at a particular stop (related to the stops weblog) and on a particular route (related to the routes weblog).

What I’m trying to do at the moment is display and format all of my data. This:

{exp:weblog:entries weblog="times" sort="asc" disable="trackbacks" search:direction="=S" search:day="=Weekday"}

{if count == "1"}
{related_entries id="stopname_times"} 
<table border="1">
<tr>
<th>Stop: {title}Direction: {direction}
Day: {day}</th>
<th>entry_id</th>
</tr>
{/if} 

{/related_entries} 
<tr>
<td>{stoptime}</td>
<td>{entry_id}</td>
</tr> 

{if count == total_results}
</table>
{/if} 

{/exp:weblog:entries}

is how I’m starting out: it lists all of the time-stops headed South on a weekday. (Direction and days that a route runs aren’t relationships - they’re just text.) However, there are hundreds of them: I need to narrow it down even further, and add the route and stop to the exp:weblog:entries tag, like

search:direction="=S" search:day="=Weekday"

.

Basically, I’m looking for the entry_id for each of the parent related entries. I’m still playing around with a custom SQL query similar to the one james brown used here: http://ellislab.com/forums/viewthread/75163/#424802. We’ll see if that works.

Thanks for your help. 😊

       
lukemcr's avatar
lukemcr
154 posts
16 years ago
lukemcr's avatar lukemcr

I’m thinking now that I could implement the route and stop information as categories associated with each weblog entry. Those are much more user-friendly.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

I’ve updated Simple Relation, which you can download here.

The new version tweaks a few things:

  • Update checking has been disabled in 1.1.2. The only setting now is whether to activate the extension on a site by site basis. Update checking may be back, but will incorporate LG Addon Updater if so.
  • Officially changed the name to MD Simple Relation.
  • Added Multi-Site awareness.
  • Added ability to “simply relate” to either weblogs or galleries.
       
Luke Hardiman's avatar
Luke Hardiman
109 posts
16 years ago
Luke Hardiman's avatar Luke Hardiman

Thanks Ryan, this extension is just what I need to properly integrate galleries with my weblog publish form..

The only problem I’m having is a clash with the LG htaccess generator extension which is causing php notices to be thrown in the control panel:

Notice: Use of undefined constant MD_SR_version - assumed 'MD_SR_version' in .../core/core.extensions.php on line 229

Notice: Use of undefined constant MD_SR_docs_url - assumed 'MD_SR_docs_url' in .../core/core.extensions.php on line 229

Notice: Use of undefined constant MD_SR_addon_id - assumed 'MD_SR_addon_id' in .../extensions/ext.md_simple_relation.php on line 73

Notice: Use of undefined constant MD_SR_extension_class - assumed 'MD_SR_extension_class' in .../extensions/ext.md_simple_relation.php on line 76

Notice: Use of undefined constant MD_SR_addon_id - assumed 'MD_SR_addon_id' in .../extensions/ext.md_simple_relation.php on line 89

I noticed there are a few .htaccess lines commented out in the ext.md_simple_relation.php file itself, around line 181

/*     if(empty($site_settings['htaccess_path']) !== TRUE && substr($site_settings['htaccess_path'], -1) != "/")
        {
            $site_settings['htaccess_path'] .= "/";
        } */

and again at line 203

//    $_SESSION['mdesign'][MD_SR_addon_id]['response'] = $this->generate_htaccess();

although not being much of an extension developer or php person I haven’t played with this code at all..

Please help!

       
Luke Hardiman's avatar
Luke Hardiman
109 posts
16 years ago
Luke Hardiman's avatar Luke Hardiman

update:

When I quote the variables to remove the notices I get a session error:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at .../engine/extensions/ext.md_simple_relation.php:1) in .../engine/extensions/ext.lg_htaccess_generator_ext.php on line 672
       
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.