Skip to content
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

Does not work with HABTM relationships #19

Open
manzapanza opened this issue Feb 7, 2013 · 10 comments
Open

Does not work with HABTM relationships #19

manzapanza opened this issue Feb 7, 2013 · 10 comments

Comments

@manzapanza
Copy link

I have a standard habtm config.
House habtm Property, with the table houses_properties and without the model HouseProperty.

On House model:
public $actsAs = array('AuditLog.Auditable' => array('Property'));

But when I change the house id = 20 changing only an association of a property in the table audits not recorded any changes!

@robwilkerson
Copy link
Owner

@manzapanza -- My apologies. I haven't been getting notified of issues or pull requests so I'm playing catch up having just noticed the activity. It looks like your config might be wrong. Try:

public $actsAs = array('AuditLog.Auditable' => array('habtm' => array('Property')));

@manzapanza
Copy link
Author

@robwilkerson Thank you for your reply! I'm tested your suggestion but seems that don't work...
I'm showing my configs:

House.php:

public $actsAs = array('AuditLog.Auditable' => array('habtm' => array('Property')));

Property.php:

public $actsAs = array('Tree', 'AuditLog.Auditable');

View/Houses/admin_edit.ctp:

echo $this->Form->create('House');
echo $this->Form->input('id');
...
echo $this->Form->input("Property", array('multiple' => 'checkbox', 'options' => $propertyOptions, 'size' => 50, 'label' => __d('House', 'Properties')));
...

HousesController.php / function admin_edit

This is the $this->request->data :
Array
(
    [House] => Array
        (
            [id] => 132
            [name] => House name
            .......
        )
    [Property] => Array
        (
            [Property] => Array
                (
                    [0] => 96
                    [1] => 94
                    [2] => 93
                    ......
                )
        )
)
$this->House->saveAll($this->request->data);

When change House data's the Json_object stored on audits table is without Property datas. like this:

stdClass Object
(
    [House] => stdClass Object
        (
            [id] => 132
            [name] => House name 2
            .....
        )
)

@robwilkerson
Copy link
Owner

Take a look at the readme. Specifically, this line in the habtm option description:

If the HABTM model is auditable in its own right, don't include it here.

It looks like that's what you're trying to do. Am I reading your code wrong?

@manzapanza
Copy link
Author

Honestly I did not understand this sentence, especially "don't include it here".
I try to explain better my config:
House habtm Property, this means that I have also a table houses_property without the model HouseProperty.
This mean that when edit an house i could made changes on tables houses and houses_property.
For this I thought that setting array('habtm' => array('Property')) on House model the behaviour start tracking changes on houses_property about the house edited.
Property have also auditable behaviour attached but is for tracking changes only on properties table.

@robwilkerson
Copy link
Owner

I don't remember the details now, but there were issues auditing both the relationship data (houses_property) and the other side of the relationship (Property) so I did something to prevent that conflict from happening. I don't recall the specifics at this point, but I'll take a look. Are you working in 1.3 or 2.x? It may cease to be an issue in 2.x.

@manzapanza
Copy link
Author

I'm working in 2.x

@angelxmoreno
Copy link

@manzapanza could you try public $actsAs = array('AuditLog.Auditable'); in your House model to see if both House and Property work fine?

@ravage84
Copy link
Contributor

@xhs345 close due to inactivity?
The code has changed quite a bit since then, but I havent' tested it for that case.

@xhs345
Copy link
Collaborator

xhs345 commented Sep 20, 2016

I think having a test case for HABTM would be good before closing this issue

@ravage84
Copy link
Contributor

True!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants