开发者

Working with relations in Symfony 1?

I need some help working with some relations in a small symfony application. I have the following structure:

Order
Customer
CustomerOrder

CustomerOrder has a PK, id, and i have two columns: order_id and customer_id from the Order and Customer tables. A customer can have many orders, while an order only has one customer. Inside my forms, how can i change them to reflect this?

  • How to add the customer in the order form?
  • How to add all the orders in the customer form开发者_高级运维?

By the way, i'm not asking how to create the schema, but how to customize the forms to match the relation behavior.


Have you looked at using the built in Many to Many relationships in Symfony 1? http://www.symfony-project.org/doctrine/1_2/en/04-Schema-Files there is a section on this page title "Many to Many". I suggest reading through that and you will likely see the answers to the questions you pose.


Both of these are pretty simple:

How to add the customer in the order form?

Assuming that your schema/model is constructed correctly, and if you've created your magic method __toString() in lib/model/Customer.class.php you should be able to see a select box of customers on your default order form.

How to add all the orders in the customer form?

Its not clear what you want here. If you want to see all the orders associated with a customer on the order form, you could create a method in CustomerOrderPeer that retrieves all the order for a specific customer, sorta like this:

$this->CustomerOrders = CustomerOrderPeer::getOrdersByCustomer($this->Customer->getId()); 

If you call this in your action, you'll pass these objects to your forms template, where you'll be able to create a table of orders for the customer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜