Closed ebadta81 closed 1 year ago
The error seems to be telling us that a string value for the primary key was delivered to implode
instead of the expected array. I see in the __get
magic method on BelongsTo
we load a non-array value into primary_key
when it's not already set, so maybe what you can do is try adding a static $primary_key = ...
property to your Product
class. Does that change anything?
It was already there, I just show you some code I thought is important.
This is the beginning of my Products class:
class Product extends model
{
static $table_name = 'webshop_products';
static $primary_key = 'product_id';
public $prefix = 'product_';
Hmm, okay. I think what you're going to have to do is put a breakpoint in that __get
magic method on BelongsTo
and see if you can work out what is happening. After the primary key lazy loads, the value of $this->primary_key
should be an array. If it's not, see if you can work backwards...
Okay,
So the problem seems like, the primary key doesn't lazy load for me. In Relationship.php BelongsTo
class load
function, when I get there, the $this->primary_key
is null. This causes the error.
I tried with this definitions, none worked:
array('brand')
array('brand', 'primary_key' => 'brand_id'),
array(
'brand',
'primary_key' => 'brand_id',
'foreign_key' => 'product_brand_id',
'class_name' => 'Brand'
),
I did set a break point in BelongsTo->__get($name)
but php never get there, so it doesn't fill there the $this->primary_key
.
Unfortunately, I've never been super-familiar with the relationship stuff. You may or may not have noticed that I've been trying to prepare a 2.0 release that modernizes the code base and fixes lots of little issues. If you want to stick with the 1.x series and really track down what's happening here you might consider rolling up your sleeves, cloning this repo, and checking out commit cc365079d15c8e758b8cd4e06b34e7c4d9be5625, which is the earliest commit in which the unit tests work. If you can come up with a breaking test that illustrates the problem here then we can issue a fix with a new 1.x patch. Alternatively, you could try the latest rc release (which is pretty solid--I'm already using it in production on my private project).
Closing due to inactivity. Freel free to reopen, @ebadta81
Hi,
I try to migrate my old php app from php 5.4 to php 8.1, and I copied the project , then installed activerecord v1.1.11 into my new project with composer.
I did a database dump and then restore, so the database is the same. On the old app, everything works fine.
In the new app Everything looks good until I get this error:
For debug info, I put a
error_log("model get name = " . $name);
into my__get()
function, so I see there is a problem at__get("brand")
.WHAT COULD BE THE PROBLEM HERE?
My
Product
class has this $belongs_to definition:And in mysql:
My brand table:
And php definition: