Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

How to save related objects?

$
0
0
Hi,

I am fighting with Yii to understand the way it works. In the book I can't find an example about how to save, delete and create related objects of a database object.

Example: I have a User and an Address. Assuming relations are set up, I want to create a user, create an address and save the relation at the same time.

How can I do this?

I thought there would be something like

$user = new User;
$user->name = 'Mike';
$address = new Address;
$address->street = 'Main road 27';
$user->save( $address );


Sure the coding does not match Yiis way of handling, but I wonder how I can do this? Same for Deleting, e.g. I want to delete a user and delete his address at the same time. Ok, this I guess I would do by ForeignKey definition.

Anyway, is there a more detailed how to somewhere about basic AR operations in combination with relationships and such?

Thanks for your help!

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>