Get id from parent in subpanel

Hi,
this is my problem, I have two custom modules (A and B) which are linked together with a one-to-many relationship.
I’m in subpanel B and would like to get the id of module A, it seemed trivial, but I can’t seem to intercept it. If the relationship is already there, so I edit and save it, I use

$bean->rel_fields_before_value['..._ida'];

and it works perfectly, but if I’m creating a new record, this field comes up empty, even though it’s inside the logic_hook after_save.
Can anyone tell me how to solve this? Thanks

I never did this, but maybe try it in another hook:

after_relationship_add
Fired after a relationship is added between two records. Note that this may be called twice, once for each side of the relationship.

Is it possible that there is no possibility of retrieving the id of the parent Module?

Maybe it’s not already there, but you can reach it with a bit more work.

You can use load_relationship to get more stuff into the bean. Or you can just use a direct SQL query.

I did a print_r on the bean, the data I need is there, but it’s very deep, I got to a certain point, but I can’t retrieve it:

$bean-><relationship_ name>->beans

and here I find:

[b0c403b7-24ac-7ec9-742a] => <ModuleA> Object
        (
            ...
            [id] => b0c403b7-24ac-7ec9-742a
            ...

I don’t know how to reach [id]

That’s just a PHP question, then

Your id is right there in the key, you don’t need to go that extra level into the bean fields

Perfect!!! It works! Thank you very much

1 Like