Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7633099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:47:22+00:00 2026-05-31T06:47:22+00:00

I’m using Codeigniter 2.1.0 along with the spark to enable PHP ActiveRecord and I

  • 0

I’m using Codeigniter 2.1.0 along with the spark to enable PHP ActiveRecord and I am unable to create a many to many association through a lookup table.
Whenever I load the Event model it fails with “Could not find the association eventcategories in model Event” which is a ActiveRecord\HasManyThroughAssociationException

In accordance to this topic I’ve tried updating my source with this patch with no effect.

I also followed this thread and based my association on the solution given there.

I’ve ended up with the following sql: http://pastebin.com/ya65VWHC
and the following models: http://pastebin.com/XEDTb6KS

I’m trying to associate one Event with several categories, for example a football game event could have the categories ‘sports’, ‘family’ and ‘fun’.

Did I miss something fundamental?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:47:24+00:00Added an answer on May 31, 2026 at 6:47 am

    I’m not able to test everything as I don’t have a database I could dump your code into (and don’t have any test data either 🙂 ), but your code has some differences with the manual.

    If you look at this page: http://www.phpactiverecord.org/projects/main/wiki/Associations#has_many_through

    You see three tables, that map like this ( I think )

     Order        -> Category   
     Payment      -> Eventcategory 
     User         -> Event
    

    A Category has multiple Events through Eventcategory, just like an Order has several Users through Payment in the example. The other way around is defined more basic (a User has Orders)

    Where you have defined 2 “through” relationships, this example only has one in the Order class, leaving the user with just a has_many. That’s a big difference I think you might need to address.

    Also, I’m not really sure about the foreign_key definitions you do in this part:

    array('events', 'foreign_key' => 'event_id',
                  array('through' => 'eventcategories', 'foreign_key' => 'event_id')
    

    Iif you’ve got the default naming scheme you don’t need to bother with explicitly naming them.

    To fix it, I would start with the order/user/payment example, check that it works for you, and then replace all the parts (carefully 🙂 ) so it becomes your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.