Welcome Guest, Not a member yet? Register   Sign In
Can I change the database for is_unique?

I'm curious could I change the database for is_unique?

I'm assuming it uses whatever the default database is. I'm using multiple databases and just curious. I'm more than fine with writing my own call backs, just curious.

No, it only allows you to select the table and field. You'd have to create your own.

even if I did $this->load->database('newdb');?

Yes, but then it would use that database for everything until you changed it again. How would you get it to use that database only for that one rule validation?

change it back after the rule?

*edit* That wouldn't work really...

But really none of my controllers are touching the database directly so it's not sticking with one programming style. I was just curious if it was possible. Most of my database calls in the models I call directly form a database object.

private $auth; // Auth Database

  function __construct() {
    // Load Databases
    $this->auth = $this->load->database('default',TRUE);

You're right that it wouldn't work because the rules don't get executed until later in the code (form_validation::run()).

If you change the database right before $this->form_validation->run() and then change it back right after (and before you do things like store/retrieve anything in the db), it might work as long as nothing else in the validation rules depend on the main database.

I think it would be best for you to create your own validation rule, or callback, for this special case. That won't interfere with anything existing and would remain more "future-proof".


Thanks for you info.

Theme © iAndrew 2016 - Forum software by © MyBB