Defining Relation Between Schema And Schema.table_Name In Restfullyii

Hi,

I have a schema defined for each customer with schema name as {customer_name}. I have a table named customer_config for each customer schema. Now my problem is I am using restfullyii and I need to define relation between the customer schema and {customer_name}.customer_config as I want to use customer_config as a sub-resource under CustomerController class. I do not have any foreign key in {customer_name}.customer_config table and I cannot define one either. Please help me with this.

Thank you.

You shouldn’t use database objects with variable names. Why can’t you add a FK to the customer_config table?

Because we generate schema based on customer names hence customer_config is already under that particular customer’s schema. Also I am not allowed to change table structure. So I do not have an option of adding FK.

For e.g. lets say customer name is ‘xyz’. Then a schema named ‘xyz’ is automatically created for this customer and all the required tables are placed under this schema. So whenever I want to select all the rows in ‘customer_config’ table of customer ‘xyz’, I will query something like this ‘select * from xyz.customer_config;’

Now the problem is as customer_config is a subresource of customer I want to access this using URL ‘<domain>/customer/xyz/customer_config’. But since there is no relation defined restfullyii is not decoding this URL.

You can define relations in AR models without having the constraints defined in the database.

How can I achieve that? Can you give me an example on how to do it?

Thank You

You should first show how your current models look like and especially their relations() method. You just add requried relations there.

I did a work around. I am using custom route to handle this special case.

Thank you for your time. I really appreciate that. :)

happy coding.