SigmaSteve
SigmaSteve

Reputation: 684

Kohana 3 Auth ORM - Can You Use A Different Database Schema?

I'm migrating a CodeIgniter application over to Kohana, and would like to take advantage of Kohana's AUTH module if possible. I have looked at the "standard" database schema that the AUTH module uses, but I already have tables and columns that contain the relevant information that are named and structured differently.

Is there a way to change where it is looking for username/password/email etc. maybe by extending Model_User and/or Kohana_Auth_ORM? I'd like to use ORM where possible.

I would like to change the table names and column names for each item, so that I can customize it fully.

If I'm forced to use the standard schema this will reduce the flexibility of my application...

I have one table called "entity" where basic details for (e.g. users, events, articles) are stored. This table does not have columns for username/password/email because these wouldn't apply to events or articles. The values for username etc. are stored in a lookup table, which maps the data in the following example way (cut down for brevity).

Table: entity
    Columns: entity_id

Table: map_entity_attribute
    Columns: entity_id, attribute_id, value

Table: attribute
    Columns: attribute_id, name

Example Data:

entity.entity_id = 99;

map_entity_attribute.entity_id = 99;
map_entity_attribute.attribute_id = 1;
map_entity_attribute.value = 'ThisIsMyUsername';

attribute.attribute_id = 1;
attribute.name = 'Username';

I hope that I have explained this clearly as I realise that the database schema is quite out of the ordinary.

Hopefully someone can point me in the right direction!

Many thanks, Steve

Upvotes: 0

Views: 235

Answers (1)

Avision
Avision

Reputation: 3703

Kohana is built in such a way that you can override almost every class in your "application" folder, and it will take precedence over classes defined in the modules: http://kohanaframework.org/3.3/guide/kohana/files

Specific to your case, you should override (not extend) the Model_User. To do so, you need to put a file name User.php in your application/Model/ folder. It should probably extend the Model_Auth_User class.

You would probably have to rewrite some of the classes but at least some of them should be usable to you as is.

Upvotes: 1

Related Questions