-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model Creation on Installation #932
Comments
Looks like the model is not fully loaded when the manipulation happens. Is the model listed in |
Addon Setup FileMy In the array returned I have the following within: 'models' => array(
'Contact' => 'Model\Contact\Contact', // Yes, the Contact.php file is in a directory such as...addon/Model/Contact/Contact.php
),
'models.dependencies' => array(
'Contact' => array(
'ee:Member'
),
) Installation TestsThe direct initialization of $members = ee('Model')->get('ee:Member')->all();
foreach($members as $member) {
$new_contact = ee('Model')->make('hat:Contact');
$new_contact->member_id = $member->member_id;
echo json_encode($new_contact->Member->getValues()); // This does work. It echos the member properties
$new_contact->save();
} Interestingly, And yes, the database values reflect what would be expected in the code above after installation. |
@RK311y You showed in your code that your model is in the namespace:
Does it work if you change it to:
|
Brief Response: the More DetailMy knowledge of namespaces in EE is somewhat limited. I have not been able to pinpoint the significants of the namespaces with regards to visibility via the core dependency injection container. What I have learned is that:
The reason I have put the FurthermoreI have made a simplified version of my addon with only the necessary component for you all to see what is happening. There is a settings controller page via the Hat addon for you to create
Note: Looking at the $member_id = ee()->input->get_post('member_id', TRUE);
$member = ee('Model')->get('ee:Member', $member_id)->first();
if(!is_null($member)) {
$contact->Member = $member;
} ConclusionThe exact problem is occurring during installation under the $member = ee('Model')->get('ee:Member')->first();
$new_contact = ee('Model')->make('hat:Contact');
// set some temporary info
$new_contact->set([
'first_name' => 'John',
'last_name' => 'Smith'
]);
//
// HERE is where the error occurs
$new_contact->Member = $member; // DOES NOT WORK
// I'll add the screen shot of the error below again
// this DOES work
//$new_contact->member_id = $member->getId();
$new_contact->save(); Screenshot of Error |
@RK311y I pulled down your addon and tested. Two changes should be able to get this to work:
And was able to get to the index, and create a model. Those two changes should allow you to create your model succesfully. |
@dougblackjr I made the I am able to work with relationships, as described here, post-installation. But during installation, I am only able to set the related key. // DOES NOT WORK
$new_contact->Member = $member;
// DOES WORK
$new_contact->member_id = $member->getId(); Can you confirm that this version installs for you? It is the same as |
@RK311y Yes, it loads for me on EE6.0.3. Can you post your error you are receiving? |
Overview
I have a custom add-on that has a Model called
Contact
. TheContact
model has a relationship toee:Member
. Upon installation, after the database table is created, aContact
model is created for eachee:Member
to which it belongs. In the previous version of EE, directly accessing the related model by its name was possible, now it is not.For example:
Addon_upd::install()
I am unable to assign the contact's member model to the relationship:
$new_contact->Member = $member
.Based on the details of the error message, I am lead to believe the
ee:Member
model does not recognize the inverse relationship which is defined in theContact
model's relationship - because it says, "The index MemberContact" is undefined. (Below, I will include my Contact model code to show the definition of the relationship)Here is a screenshot of the error I receive:
Contact Model Code
Problem Narrowed
This problem does not occur after the addon is installed. I am able to access/assign this relationship once the addon is installed.
i.e. this code runs just fine afterwards:
Furthermore
This was not a problem prior to EEv6. So maybe it has something to do with the new
ExpressionEngine\Service\Addon\Installer
.... but I do not know...The text was updated successfully, but these errors were encountered: